python运行列表的结果不同_python 3 代码一模一样,出现运行结果不同的情况(只是不以为一样而已)...
下面代碼:
money = 3
total_money = 0
for i in range(40):#一個月坐車40次
if total_money < 100:#單程100內不打折
total_money += money
elif total_money >= 100 and total_money < 150:#100到150打8折
total_money += money * 0.8
elif total_money >= 150 and total_money < 400:#150到400打5折
total_money += money * 0.5
elif total_money >= 400:#超過400后不打折
total_money += money
print("小明一個月坐車車費:%2.f" % total_money)
運行結果:小明一個月坐車車費:116
下面代碼:
total_money = 0
money = 3
for i in range(40):
if total_money < 100:
total_money += money
elif total_money >= 100 and total_money < 150:
total_money += money * 0.8
elif total_money >= 150 and total_money < 400:
total_money += money * 0.5
elif total_money >= 400:
total_money += money
print('小明消費:%.2f' % total_money)
運行結果:小明消費:116.40
最后發現是個烏龍,大意了一點點,犯了個低級錯誤
是最后的格式化輸出%.2f寫成了%2.f
當引以為戒
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的python运行列表的结果不同_python 3 代码一模一样,出现运行结果不同的情况(只是不以为一样而已)...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 斐讯k2路由器怎样电脑设置斐讯k2路由器
- 下一篇: 盘点韩国的传奇IP游戏韩国网游传奇