「Python」演算子を使うサンプル
サンプルコード
# coding: utf-8 #!/usr/bin/python3 a = 20 b = 10 c = 15 d = 5 e = 0 e = (a + b) * c / d #( 30 * 15 ) / 5 print ("(a + b) * c / d 計算結果:", e) e = ((a + b) * c) / d # (30 * 15 ) / 5 print ("((a + b) * c) / d 計算結果:", e) e = (a + b) * (c / d) # (30) * (15/5) print ("(a + b) * (c / d) 計算結果:", e) e = a + (b * c) / d # 20 + (150/5) print ("a + (b * c) / d 計算結果:", e)
実行結果
>python 101.py
(a + b) * c / d 計算結果: 90.0
((a + b) * c) / d 計算結果: 90.0
(a + b) * (c / d) 計算結果: 90.0
a + (b * c) / d 計算結果: 50.0