samedi 27 janvier 2018

Elif statements in Python are not working for a tip calculator. Any clue as to what I am doing wrong? (Beginner programming university student here.)

I am a beginner programmer who has just started taking classes at a University in Utah. I am supposed to program a calculator that will calculate the amount that you should tip based on the quality of service received. I keep getting errors at around line 12 that state that the 'elif' is an invalid syntax. I am not exactly sure what I am doing wrong, but then again, I do not know much in the first place. I apologize if my code might be atrocious or perhaps flat out wrong entirely. I suppose this is all a learning process for me. I've been doing a lot of digging around on the internet to see what I could find to figure out what I am doing wrong, but I have not found it out, yet. (I've tried several variations of the code to see what might or might not work, but this is, essentially, what I have put together and have been working off of.)

Thanks to all who (hopefully) help me see the light of what this novice is doing wrong.

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()

Aucun commentaire:

Enregistrer un commentaire