如何列印出包含在字串末尾的小費的賬單的四舍五入總數?
bill = input('Enter in the bill ($): ')
tip = input('Enter in the tip percentage (%): ')
total_price = float(bill) * int(tip) / 100 float(bill)
print(f"The total cost for dinner is ${total_price}")
我希望結果是“晚餐的總費用是 $ x.xx ”,其中x取決于輸入的數字。
我不確定在我的列印陳述句中添加 round() 函式的位置。
uj5u.com熱心網友回復:
你可以簡單地做
print(f"... ${total_price:.2f}")
或者
print(f"... ${round(total_price, 2)}")
編輯:感謝您指出我的錯誤 ddejohn。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/492575.html
