You work for a bakery that sells two items: muffins and cupcakes. The number of muffins and cupcakes in your shop at any given time is stored in the <span style="text-decoration: none;">variables</span> muffins and cupcakes, which have been defined for you.
Write a program that takes strings from standard input indicating what your customers are buying ("muffin" for a muffin, "cupcake" for a cupcake). If they buy a muffin, decrease muffins by one, and if they buy a cupcake, decrease cupcakes by 1. If there is no more of that baked good left, print ("Out of stock").
Once you are done selling, input "0", and have the program print out the number of muffins and cupcakes remaining, in the form "muffins: 9 cupcakes: 3" (if there were 9 muffins and 3 cupcakes left, for example).
muffins = 3
cupcakes = 3
a = input("Enter the item: ")
while a != '0' or (muffins==0 and cupcakes==0):
if a == 'muffin':
if muffins>0:
muffins-=1
else:
print("Zero muffins.")
if a == 'cupcake':
if cupcakes>0:
cupcakes-=1
else:
print("Zero cupcakes.")
a = input("Enter the item: ")
if muffins==0 and cupcakes==0:
print("Out of stock")
break
print("muffins: %d cupcakes: %d" %(muffins, cupcakes))
Comments
Leave a comment