Calculate Bill

Chris Angelico rosuav at gmail.com
Tue Mar 29 19:34:23 EDT 2016


On Wed, Mar 30, 2016 at 9:33 AM, Yum Di <nevinadias3 at gmail.com> wrote:
> Hey.. this code works. However, i need it to calculate the total cost.
> I dont know how to do that. Can someone help me..
> thanks

It does indeed appear to work. And thank you for posting your current
code. However...

> print ("Welcome to Pizza Shed!")
>
> order = raw_input ("\n\nPLEASE PRESS ENTER TO ORDER." )
>
> tablenum = input ("Enter table number from 1-25 \n ")

This should never be done. Do not do this. Your use of raw_input
proves that you're using Python 2, and in Python 2, never ever ever
use input(). There are two solutions:

1) Use raw_input everywhere
2) Use Python 3, and add parentheses to the few print() calls that
don't have them.

Either way, the correct fix also involves accepting *strings* from the
keyboard, and then converting them. The problem with input() is that
it automatically converts what the user types, according to the rules
of source code; you almost never want this. For example, entering 08
will result in an error, but 08.50 is the same as 8.50.

After that, you can start looking at the totals. But I'm not going to
write the code for you; you can start writing code, and when you get
stuck, come and ask for help.

ChrisA



More information about the Python-list mailing list