Python Forum
Help With MyProgrammingLab Code Problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help With MyProgrammingLab Code Problem
#1
I am taking a class to learn python and am in need of help. I have code and am getting errors with MyProgrammingLab. I am pretty new to python and am stuck.

Here is the question I have:

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



The error I am getting is this:

SyntaxError: invalid syntax (CTest.py, line 6)
6 elif:

There are probably other issues with my code other than this, but this is the current one I am trying to fix. I tried removing possible spaces and there were none, I only used tabs. I am not sure why I am getting the error.

Here is the code I have:

buying = input()
while buying != "0":
	if buying == "muffin":
		if muffin > 0:
			muffin -= 1 #If someone asks for a muffin then the amount of muffins should go down by 1
	elif: # this line has the error
		print ("Out of stock")

	elif:
		buying == "cupcake":
	
	elif:
		cupcake > 0:
		cupcake -= 1
  # If someone asks for a cupcake then the amount of cupcakes should go down by 1
	else:
		print ("Out of stock")
		buying = input()

		print("muffins:", muffins, "cupcakes:", cupcakes)
Reply
#2
use '#' for comments, not '*/' and '/*'
Only one need at start of comment, can start anywhere on line, and will remain a comment until end of line
Reply
#3
elif is still an if statment so it requires a test of some sort. The elif by itself is the error. Here is an example :

muffins = 13
cupcakes = 13

while True:
	buying = input ()
	if buying == "0" :
		break
	elif 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")
 
print("muffins:", muffins, "cupcakes:", cupcakes)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  MyProgrammingLab wont accept anything I put in chicks4 2 11,583 Feb-10-2019, 11:44 PM
Last Post: chicks4

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020