PYTHON : Write a function orderPizza that allows the user input to build a pizza
ID: 3689636 • Letter: P
Question
PYTHON :
Write a function orderPizza that allows the user input to build a pizza. It then prints a thank you message, the cost of the pizza and then returns the Pizza that was built.
>>> orderPizza()
Welcome to Python Pizza!
What size pizza would you like (S,M,L): M
Type topping to add (or Enter to quit): mushroom
Type topping to add (or Enter to quit): onion
Type topping to add (or Enter to quit): garlic
Type topping to add (or Enter to quit):
Thanks for ordering!
Your pizza costs $14.299999999999999
Pizza('M',{'mushroom', 'onion', 'garlic'})
>>> orderPizza()
Welcome to Python Pizza!
What size pizza would you like (S,M,L): L
Type topping to add (or Enter to quit): calamari
Type topping to add (or Enter to quit): garlic
Type topping to add (or Enter to quit):
Thanks for ordering!
Your pizza costs $16.65
Pizza('L',{'garlic', 'calamari'})
>>> p=orderPizza()
Welcome to Python Pizza!
What size pizza would you like (S,M,L): S
Type topping to add (or Enter to quit):
Thanks for ordering!
Your pizza costs $6.25
>>> p
Pizza('S',set())
>>>
Explanation / Answer
def orderPizza():
print "Welcome to Python Pizza!"
p = 0
size = raw_input('What size pizza would you like (S,M,L): ')
if(p =='S'):
p = 5
elif(p=='M'):
p = 10
else:
p = 15
list = []
while(True):
t = raw_input("Type topping to add (or Enter to quit):")
if(t==""):
break
list.append(t)
p = p + 2
print "Thanks for ordering!"
print "Your pizza costs $",p
print "Pizza('",size,"',",list,")"
orderPizza()
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.