※ 宣告值
meal = 44.50; # 宣告一個值為44.50
tax = 0.0675; # 宣告一個 6.75% 的值,要宣告為0.0675
tip = 0.15; # 宣告一個 15% 的值, 要宣告為0.15
_________________________________________
※ 設一個變數 itself 且itself 等於meal,並套用到 meal =itself+itself*tax
meal = 44.50
tax = 0.0675
tip = 0.15
itself=44.5;
meal =itself+itself*tax
---------------------------------------------------------
Result:47.50375
_________________________________________
※ 設一個變數 total ,算出meal+meal*tip 並印出來
# Assign the variable total on line 8!
meal = 44.50
tax = 0.0675
tip = 0.15
meal = meal + meal * tax # 等於上題的meal =itself+itself*tax
total = meal+meal*tip # 求出和
print("%.2f" % total) # 印出小數點後兩位
---------------------------------------------------------
Result: 54.63
_________________________________________
你好,我也正在学这里,total里面的meal*tip直接使用不会代用前面加上tax的那个meal么
回覆刪除