102k views
0 votes
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 variables 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).

User Zan Lynx
by
5.1k points

2 Answers

4 votes

Answer:

buying = input()

while buying != "0":

if buying == "muffin":

if muffins > 0:

muffins -=1

else:

print("Out of stock")

elif buying == "cupcake":

if cupcakes > 0:

cupcakes -=1

else:

print("Out of stock")

buying = input()

print("muffins:", muffins, "cupcakes:", cupcakes)

Step-by-step explanation:

The program above can be used to determine if a customer will buy a muffin or cupcakes at any given point in time. The program was developed by considering several factors that influence customer's decision such as the number of cupcakes and muffins available as well as the total number of customers' requests at any given time.

User Alonisser
by
5.0k points
4 votes

I created this program in Python.

SMuffin = 10

SCake = 1

NewTrans = 'y' #New transaction added for multiple inputs

while NewTrans == 'y': #While is used for multiple transactions until the user inputs "0".

Scheck = str(input("Enter cupcake or muffin: "))

if Scheck == 'cupcake':

if SCake == 0:

print("Out of stock")

else:

print("Cupcake Sold")

SCake -= 1

elif Scheck == 'muffin':

if SMuffin == 0:

print("Out of stock")

else:

print("Muffin Sold")

SMuffin -= 1

elif Scheck == '0':

print("Muffins:",SMuffin,"Cupcakes:",SCake)

else:

print("Invalid input!")

NewTrans = str(input("New Transaction?: (y/n)"))

if NewTrans == 'n':

print("Muffins:",SMuffin,"Cupcakes:",SCake)