package sample;
public class Hello {
public static void main(String[] args) {
int old, height;
old = 20;
height = 184;
System.out.println(“年齢:” + old);
System.out.println(“慎重:” + height);
}
}
package sample;
public class Hello {
public static void main(String[] args) {
int old, height;
old = 20;
height = 184;
System.out.println(“年齢:” + old);
System.out.println(“慎重:” + height);
}
}
def calc(n, func):
# return double(10)
return func(n)
print(calc(10, lambda n: n * 2)) #無名関数
print(calc(10, lambda n: n * 3))
def double(n):
return n * 2
def triple(n):
return n * 3
def calc(n, func):
#return double(10)
return func(n)
print(calc(10, double))
print(calc(10, triple))
def double(n):
return n * 2
twice = double
print(twice(20))
def get_price(a, b, rate):
# 仮引数、値が代入された変数 → ローカル変数
# 値が代入されていない変数 → 外のスコープを探す
#global rate
if a + b >= 3000:
rate = 1.05
total = (a + b) * rate
return total
rate = 1.1
print(get_price(300, 700, rate))
print(get_price(3000, 7000, rate))
print(rate)
def get_price(a, b):
# 仮引数、値が代入された変数 → ローカル変数
# 値が代入されていない変数 → 外のスコープを探す
global rate
if a + b >= 3000:
rate = 1.05
total = (a + b) * rate
return total
rate = 1.1
print(get_price(300, 700))
print(get_price(3000, 7000))
print(rate)
def get_price(a, b):
# 仮引数、値が代入された変数 → ローカル変数
# 値が代入されていない変数 → 外のスコープを探す
if a + b >= 3000:
rate = 1.05
total = (a + b) * rate
return total
rate = 1.1
print(get_price(300, 700))
using namespace std;
void sayHello(int times) {
for (int i = 0; i < times; ++i) {
cout << “Hello, World\n”;
}
}
int main()
{
sayHello(5);
}
using namespace std;
int main()
{
int i = 0;
do {
cout << “Hello, World\n”;
++i;
} while (i < 5);
}
using namespace std;
int main()
{
int i = 0;
while(i < 5){
cout << “Hello, World\n”;
i++;
}
}