简体   繁体   English

基于服务的小费计算器 Python

[英]Tip Calculator Python Based on Service

My 2nd question is to create a tip calculator based on the service.我的第二个问题是根据服务创建一个小费计算器。 If the service is amazing then compute a 20% tip, if its okay compute a 15% tip and if its horrible compute a 10% tip.如果服务很棒,则计算 20% 的小费,如果可以,则计算 15% 的小费,如果服务很差,则计算 10% 的小费。


EDIT: From Raj's comment on the other post with his code:编辑:从 Raj 用他的代码对另一篇文章的评论:

Heres what I have done for the questions这是我为这些问题所做的

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 Mar 8 at 6:22 – 拉吉 3 月 8 日 6:22

Instead of the while loop you have in your code:而不是您的代码中的 while 循环:

while service = amazing:

You should replace it with an你应该用一个替换它

if .. :

elif ..:

else:

statement, and when testing for equality of a string value, you need to set it in quotes.语句,并且在测试字符串值的相等性时,您需要将其设置在引号中。

if service == "amazing":

Code below is what you (Raj) had on the other post linked at the top.下面的代码是您(Raj)在顶部链接的另一篇文章中所拥有的。 I tried to edit your question, but it got rejected.我试图编辑你的问题,但被拒绝了。


Code below is from Raj's comment on his other post :下面的代码来自 Raj 在他的另一篇文章中的评论:

Heres what I have done for the questions这是我为这些问题所做的

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 Mar 8 at 6:22 – 拉吉 3 月 8 日 6:22

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM