我在运行此程序时遇到问题[关闭]

问题描述 投票:-4回答:1
# Tipper Program
# User enters the bill total and the program computes two amounts,
# a 15 percent tip and a 20 percent tip

print("\t\t\t **  **  **  **  **  **  **  **  **  **")

print("\n\t\t\t\t    Tip Calculator")

print("\n\t\t\t **  **  **  **  **  **  **  **  **  **")

bill = input("\nPlease enter your restaurant's bill total: ")

tip_15 = bill * 0.15

tip_20 = bill * 0.20

float(print("\n\nA 15% tip for this bill comes out to ", tip_15))
float(print("\nA 20% tip for this bill comes out to ", tip_20))


input("\n\nPress the enter key to exit.")

在我输入账单总数后,应用程序会保持关闭状态。有什么建议可以解决这个问题?

python python-3.x input casting user-input
1个回答
3
投票

当您要求用户输入时,您需要将此值转换为浮点数,然后再乘以0.15和0.20

bill = float(input("\nPlease enter your restaurant's bill total: "))

并且你的最后2行不应该被转换成浮点数

print("\n\nA 15% tip for this bill comes out to: ", tip_15)
print("\nA 20% tip for this bill comes out to: ", tip_20)
© www.soinside.com 2019 - 2024. All rights reserved.