为什么if语句总是评估为true?

时间:2018-01-28 03:09:34

标签: python if-statement

我应该编制一个计算器,根据收到的服务质量计算你应该提示的金额。

我一直在第12行附近发现错误,说明了这些错误。是一种无效的语法。我不确定我做错了什么,但话说回来,我一开始并不知道多少。

我一直在互联网上做很多事情,看看我能找到什么来弄清楚我做错了什么,但我还没有找到它。 (我已经尝试了几种代码的变体,看看哪些可能会起作用,哪些起作用,但这基本上就是我放在一起并且一直在起作用的。)

def main () :
  print ("This program calculates tips based upon the")
  print ("quality of the service provided.")
  principal = float (input ("Enter the price of your meal: $") )
  service = (input ("Enter whether your service was Poor, Average, or Excellent: "))
  Exceltip=(principal*1.2)
  avgtip=(principal*1.15)
  poortip=(principal*1.1)
  if service == Excellent or excellent:
    print("Tip = ", Exceltip)
    print("The cost of your meal including a tip will come to: $", round((principal+Exceltip),2)
  elif service == Average or average:
    print("Tip = ",avgtip)
    print("The cost of your meal including a tip will come to: $", round((principal+avgtip),2)
  elif service == Poor or poor :
      print("Tip = ", poortip)
      print("The cost of your meal including a tip will come to: $",round((principal+poortip)2)
  else print("The input is invalid."")
main()

0 个答案:

没有答案