I'm trying to teach my son how to program & I gave him a challenge that I can't do myself.
He has to prompt the user to enter A, B, or C. Depending on their choice, he'll print some results & other stuff. While we got this working, I'm trying to do some error handling & check for cases where the input is not A, B, or C. The code is listed below. I certainly appreciate any guidance you can offer.
print "************************************************************"
print "* *"
print "* Welcome to the cinemas *"
print "* *"
print "************************************************************"
print "* *"
print "* What movie would you like to see ? *"
print "* *"
print "* A) Star Wars *"
print "* B) Bourne Identity *"
print "* C) The Hunger Games *"
print "* *"
print "************************************************************"
movie=raw_input()
while(movie!="A","B","C"):
print "************************************************************"
print "* *"
print "* Welcome to the cinemas *"
print "* *"
print "************************************************************"
print "* *"
print "* What movie would you like to see ? *"
print "* *"
print "* A) Star Wars *"
print "* B) Bourne Identity *"
print "* C) The Hunger Games *"
print "* *"
print "************************************************************"
movie=raw_input()
print "************************************************************"
print "* *"
print "* How many tickets would you like ? *"
print "* *"
print "************************************************************"
quantity =input()
cost = 7.5
if movie =="A":
print "You are seeing Star Wars"
price = cost*quantity
print "You owe ", price
elif movie =="B":
print "You are seeing Bourne Identity"
price = cost*quantity
print "You owe ", price
elif movie =="C":
print "You are seeing The Hunger Games"
price = cost*quantity
print "You owe ", price
"""blah""") - use them rather than a load ofprintstatements! (Better yet, generate those strings automatically - you are changing very little).{"A": "Star Wars", "B": "Bourne Identity", "C": "The Hunger Games"}would seem appropriate here.input()in 2.x is a bad idea! If you want an integer of the user, then useint(raw_input())instead!ast.literal_eval(raw_input(...or when the desired type is known, explicitly use that oneinput()was removed from 3.x in that form (it functions likeraw_input()from 2.x).