hey everybody
I'm taking a computer class right now and one of the projects I need to do is

create a very simple pizza-ordering menu.
At this pizzeria, there is only one kind of pizza you can order:
regular (cheese) with no toppings. Your choices are what size of
pizza, and how many of them. Your program will need to figure out the
total price of the order. A small pizza costs $7.99, a medium $14.99,
and a large $18.99.

The program will begin by printing "Let me help you order a pizza.
Here are the choices: (a) small $7.99; (b) medium $14.99; (c) large
$18.99. Please enter a or b or c:".

Then the user will type "a" or "b" or "c" (followed by the <enter>
key). For example, suppose the user types "b" <enter>. Then the
program will print "Ok, medium, that is $14.99 each."

Then the program will print "Ok, medium, that is $14.99 each.
How many would you like?"

Then the user will type a number (followed by the <enter> key). For
example, suppose the user types "2" <enter>.

Then the program will print "Your total is $29.98. Press <enter> to
exit."

Then the user will type the <enter> key, and the program will halt.

Programming the assignment:

In this lab,
you will be using the raw_input function to get the response to each
question, and to put up the final "Press enter to exit" message.

There is more than one way to write this program, so we won't give you
step-by-step instructions. Here are some general hints:

You will need at least two variables, one to keep track of the size
of pizza, and another to keep track of number of pizzas.

You will probably want to use some sort of if-elif-else logic to
decide what the price is, based on the size of pizza ordered.

The raw_input function returns a string, and you need a number (of
pizzas.)

so far, i only got this

Menu=raw_input("Let me help you order a pizza. Here are the choices (a) small $7.99 (b) medium $14.99 (c) large $18.99. Please enter a or b or c:")
Let me help you order a pizza. Here are the choices (a) small $7.99 (b) medium $14.99 (c) large $18.99. Please enter a or b or c:
>>> a=raw_input("Ok, small, that is $7.99 each. How many would you like?")
Ok, small, that is $7.99 each. How many would you like?
>>> b=raw_input("Ok, medium, that is $14.99 each. How many would you like?")
Ok, medium, that is $14.99 each. How many would you like?
>>> c=raw_input("Ok, large, that is $18.99 each. How many would you like?")
Ok, large, that is $18.99 each. How many would you like?
>>> 2=raw_input("Ok, your total is $29.98.")

I'm not even sure if it is right. Thank you in advance, any help would be appreciated.

Recommended Answers

All 7 Replies

First it's a pain to read in normal text, use the code=python tags. Your code is also entirely wrong. Use something more like x = raw_input, then an if statement to decide what you typed and call a function to do the math. It's a pretty basic program so you should be able to figure it out by looking at the "Starting Python" sticky.

That looks like you have the general idea, you just need to format the code right.
First I would write the menu using print statements, and then get the answer with an raw_input statement

print 'for small press "a"'
print 'for medium press "b"'
print 'for large press "c"'
choice=raw_input()

and then use the if-elif-else statements like your teacher said to decide where to go from there

and for your variables where you are using like a, b, c etc. You should use something that makes more sense. For instance if I was doing this project I would use variables like
"NumberOfSmall" or "countSmall" for keeping track of how many small pizzas they want, and the same for the others. Just so you don't confuse yourself later on (i've done that to myself way too many times)

def choose_pizza(pizza,menu):
  print("Let me help you order a pizza. Here are the choices:")
  for (pizzaname,prize),menuitem in zip(pizza.iteritems(),menu.keys()):
    print("(%s) %s $%.2f" % (menuitem,pizzaname,prize))
  choice=raw_input("Please enter %s: " % (" or ".join(menu.keys())))
  if choice not in menu:
    return None
  return choice

def choose_qty():
  qty=raw_input("How many would you like?: ")
  iqty=None
  try: iqty=int(qty)
  except ValueError: return None
  return iqty

def main():
  pizza={'small':7.99,'medium':14.99,'large':18.99}
  menu={'a':'small','b':'medium','c':'large'}
  choice=None
  while not choice:
    choice=choose_pizza(pizza,menu)
  print("Ok, %s, that is $%.2f each." % (menu[choice],pizza[menu[choice]]))
  qty=None
  while not qty:
    qty=choose_qty()
  print("Your total is $%.2f." % (pizza[menu[choice]]*qty))
  print("Press <enter> to exit.")
  raw_input()
main()

LOL, I like to see the teacher's face if jimbox123 turns in slate's code as homework!

I have done it because:

1. It was fun for 10 minutes
2. Good way to learn is to read a clean code that solves specifically your problem
3. It was my first post, wanted something noteworthy.

yeah I did it too but my code was slot simpler than yours. LOL mine would actually be believable as a students code if he turned It in...but I don't want other people to cheat cause of me so I won't post it

Hey slate, nice code. You sure pulled a number of Python features out of the box.

I am always amazed how many ways there are to solve a problem. Just don't stop learning.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.