generated at
Pythonの変数を使ってみよう
変数を使うことで、計算結果を覚えておいて再利用することができる。
問題
リンゴ(apple)を4個と、オレンジ(orange)を2個買い、買った合計は700円でした。
オレンジは100円です。
リンゴ1個の値段は、いくらでしょう。
オレンジ1個は100円
オレンジ1個の値段を変数orangeに代入する
>>>> orange=100
リンゴ4個は、合計からオレンジ2個分の値段を引いた値
>>>> apple4 = 700 - (orange * 2)
リンゴ1個の値段は、リンゴ4個の金額を4で割った値
>>>> apple = apple4 / 4
>>>> print(apple)
>125.0
リンゴ1個の値段は、125円
検算
>>>>print(apple * 4 + orange * 2)
>700.0