第二章讀書筆記
超市抹零結賬
money_all = 56.75 + 72.91 + 88.50 + 26.37 + 68.51
money_all_str = str(money_all)
print("商品總金額為:"+money_all_str)
money_real = int(money_all)
money_real_str = str(money_real)
print("實收金額為:"+money_real_str)
print("3105")
計算學生成績的分差及平均分
python = 95
english = 92
c = 89
sub = python - c
avg = (python + english + c)/3
print("Python課程和C語言課程的分數之差:"+str(sub)+"分\n")
print("3門課的平均分:"+str(avg)+"分")
print("3105")
比較運算子比較大小關係
python = 95
english = 92
c = 89
print("python ="+str(python)+"english ="+str(english)+"c ="+str(c)+"\n")
print("python < english的結果:"+str(python < english))
print("python > english的結果:"+str(python > english))
print("python == english的結果:"+str(python == english))
print("python != english的結果:"+str(python != english))
print("python <= english的結果:"+str(python <= english))
print("english >= c的結果:"+str(python >=c))
print("3105")
手機店的打折活動
print("\n手機店正在打折,活動進行中……")
strWeek = input("請輸入中文星期(如星期一):")
intTime = int(input("請輸入時間中的小時(範圍:0~23):"))
if (strWeek == "星期二" and (intTime >= 10 and intTime <= 11)) or (strWeek == "星期五"
and (intTime >= 14 and intTime <= 15)):
print ("恭喜你,獲得了折扣活動參與資格,快快選購吧!")
else:
print("對不起,您來晚了一步,期待下次活動……")
print("3105")