我在运行此程序时遇到问题

时间:2017-12-07 00:45:36

标签: python python-3.x input casting user-input

# 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.")

在我输入帐单总数后,应用程序会继续关闭。有什么建议可以解决这个问题吗?

1 个答案:

答案 0 :(得分: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)