我的第二个问题是根据服务创建小费计算器。如果服务是惊人的,那么计算20%的小费,如果它可以计算15%的小费,如果它的可怕计算10%的小费。
编辑:来自Raj的评论on the other post及其代码:
以下是我为问题所做的事情
rbill = float(input("What is the total bill?"))
print("What was the level of service?")
service = input("Please choose amazing, okay, or horrible:")
while service = amazing:
tip=(bill*0.20)
total=(bill+tip)
print("The bill was $",bill)
print("The service was",service)
print("The tip is",tip)
print("The grand total with the tip is $",total)
- Raj 3月8日6:22
答案 0 :(得分:0)
而不是代码中的while循环:
while service = amazing:
您应该用
替换它if .. :
elif ..:
else:
语句,当测试字符串值的相等性时,需要将其设置为引号。
if service == "amazing":
以下代码是您(Raj)在顶部链接的其他帖子上的内容。我试图编辑你的问题,但它被拒绝了。
以下代码来自Raj的评论on his other post:
以下是我为问题所做的事情
rbill = float(input("What is the total bill?"))
print("What was the level of service?")
service = input("Please choose amazing, okay, or horrible:")
while service = amazing:
tip=(bill*0.20)
total=(bill+tip)
print("The bill was $",bill)
print("The service was",service)
print("The tip is",tip)
print("The grand total with the tip is $",total)
- Raj 3月8日6:22