関数名
def double(n):
return n * 2
#print(double(10))
twice = double
print(twice(20))
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++;
}
}
using namespace std;
int main()
{
const int N = 9;
for (int i = 1; i <= N; ++i) {
for (int j = 1; j <= N; ++j) {
cout << setw(3) << i * j;
}
cout << endl;
}
}
def get_price(a, b):
total = (a + b) * rate
return total
rate = 1.1
print(get_price(300, 700))
using namespace std;
int main()
{
for (int i = 1; i <= 100; ++i)
{
if (i % 15 == 0) {
// 3でも5でも割り切れる場合はFizzBuzzを出力
cout << “FizzBuzz\n”;
}
else if (i % 3 == 0) {
// 3で割り切れる場合はFizzを出力
cout << “Fizz\n”;
}
else if (i % 5 == 0) {
// 5で割り切れる場合はBuzzを出力
cout << “Buzz\n”;
}
else {
// それ以外の場合は数値を出力
cout << i << endl;
}
}
return 0;
}