Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #106016

Re: Calculate Bill

From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Subject Re: Calculate Bill
Date 2016-03-30 10:34 +1100
Message-ID <mailman.171.1459294472.28225.python-list@python.org> (permalink)
References <ba29ab8f-1076-4a00-8b2e-b4bbe0fbae60@googlegroups.com>

Show all headers | View raw


On Wed, Mar 30, 2016 at 9:33 AM, Yum Di <nevinadias3@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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Calculate Bill Yum Di <nevinadias3@gmail.com> - 2016-03-29 15:33 -0700
  Re: Calculate Bill Chris Angelico <rosuav@gmail.com> - 2016-03-30 10:34 +1100
  Re: Calculate Bill Steven D'Aprano <steve@pearwood.info> - 2016-03-30 11:50 +1100
  Re: Calculate Bill BartC <bc@freeuk.com> - 2016-03-30 11:19 +0100

csiph-web