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


Groups > comp.lang.python > #105999 > unrolled thread

Help with python code

Started byokdk <nevinadias3@gmail.com>
First post2016-03-29 14:00 -0700
Last post2016-03-29 21:37 +0000
Articles 6 — 5 participants

Back to article view | Back to comp.lang.python


Contents

  Help with python code okdk <nevinadias3@gmail.com> - 2016-03-29 14:00 -0700
    Re: Help with python code BartC <bc@freeuk.com> - 2016-03-29 22:19 +0100
    Re: Help with python code Rob Gaddi <rgaddi@highlandtechnology.invalid> - 2016-03-29 21:19 +0000
      Re: Help with python code Wildman <best_lay@yahoo.com> - 2016-03-29 17:51 -0500
    Re: Help with python code Yum Di <nevinadias3@gmail.com> - 2016-03-29 14:32 -0700
      Re: Help with python code Rob Gaddi <rgaddi@highlandtechnology.invalid> - 2016-03-29 21:37 +0000

#105999 — Help with python code

Fromokdk <nevinadias3@gmail.com>
Date2016-03-29 14:00 -0700
SubjectHelp with python code
Message-ID<a4b1ac8d-bf43-4b1f-8e60-394d1a740dca@googlegroups.com>
This is my code
import random
import time

pizzatype = [3.50,4.20,5.20,5.80,5.60]
drinktype = [0.90,0.80,0.90]
topping = [0.50,0.50,0.50,0.50]

def Total_cost_cal (pt ,dt ,t):
    total = pt + dt + t
    return total

print ("Welcome to Pizza Shed!")

order = raw_input ("\n\nPLEASE PRESS ENTER TO ORDER." )

tablenum = input ("Enter table number from 1-25 \n ")
while tablenum>25 or tablenum <=0:
    tablenum = input ("Enter the correct table number, there are only 25 tables ")
    
#Pizza menu with prices

print ("---------------------")

print ("Let me help you with your order!")

print ("---------------------")

order = raw_input ("\n\nPLEASE PRESS ENTER TO SELECT YOUR PIZZA." )

print ("Menu")

print (
    "1 = cheese and tomato: 3.50, "
    "2 = ham and pineapple: 4.20, "
    "3 = vegetarian: 5.20, "
    "4 = meat feast: 5.80, "
    "5 = seafood: 5.60 " )

menu = input("Enter the type of pizza that you want to order from 1-5 \n")
while menu>5 or menu <=0:
    menu = input ("Enter the right number ")
pizza_cost = pizzatype[menu]
    
print ("------------------")

pizza_amount = input ("Enter the amount of Pizzas that you want to order ")
while pizza_amount > 10 or pizza_amount <=0:
    pizza_amount = input ("Maximum amount is 10, Please enter again ")

print ("--------------------")

#base

print ("Base")

print (
    "1 = thin and crispy,"
    "2 = traditional" )

base = input ("Select a base from 1-2 \n")
while base>2 or base<=0:
    base = input ("There are only 2 types, Please enter again ")

print ("-------------------")

#extra toppings

print ("Extra Toppings")

toppings = input ("Enter a number for your choice of extra topping \n Enter 1 for extra cheese \n Enter 2 for extra pepperoni \n Enter 3 for extra pineapple \n Enter 4 for extra peppers \n" )
while toppings >4 or toppings < 0:
    toppings = input ("There are only 4 types of extra toppings, Please try again " )
topping_cost = topping[toppings]

print ("-------------------------")

#drink

print ("Drink")

print (
    "1 = Cola: 0.90, "
    "2 = Lemonande: 0.80, "
    "3 = Fizzy Orange: 0.90 "
    )

drink = input ("Enter a number for your choice of drinks " )
while drink>3 or drink<0:
    drink = input ("Choices start from 0 to 3 " )
drink_cost = drinktype[drink]
drink_amount = input ("Enter the amount of drinks")
while drink_amount >10 or drink_amount<0:
    drink_amount = input (" You can only have upto 10 drinks, Please try again")
    

print ("--------------------------------")

pizzatotal = pizza_cost*pizza_amount
drinktotal = drink_cost*drink_amount

total_cost = total_cost_cal(pizzatotal, drinktotal, topping_cost)

print ("--------------------------------")
print ("Calculating bill")
print ("--------------------------------")
print ("--------------------------------")

print ("Thank You for ordering at Pizza Shed! ")


Howeve, it doesnt seem to be working. It doesnt calculate the bill. I dont know what to do, as I'm less than average at this.
it comes up as IndexError: list index out of range at line42

Please help

[toc] | [next] | [standalone]


#106000

FromBartC <bc@freeuk.com>
Date2016-03-29 22:19 +0100
Message-ID<nderbv$hnm$1@dont-email.me>
In reply to#105999
On 29/03/2016 22:00, okdk wrote:

> pizzatype = [3.50,4.20,5.20,5.80,5.60]
> drinktype = [0.90,0.80,0.90]
> topping = [0.50,0.50,0.50,0.50]

> total_cost = total_cost_cal(pizzatotal, drinktotal, topping_cost)
>
> print ("--------------------------------")
> print ("Calculating bill")
> print ("--------------------------------")
> print ("--------------------------------")
>
> print ("Thank You for ordering at Pizza Shed! ")
>
>
> Howeve, it doesnt seem to be working. It doesnt calculate the bill. I dont know what to do, as I'm less than average at this.
> it comes up as IndexError: list index out of range at line42

Those lists you define are indexed from 0, not 1 as you seem to assume. 
(So you get an index error if choosing pizza type 5).

You might try inserting a dummy 0 at the start (so the rest are indexed 
from 1), but better to change the logic.

Also total_cost_cal() is not defined anywhere. (And the user interface 
is generally untidy with poor error checking, but this can be cleaned up 
later.)

(I also found I was obliged to choose an extra topping. Suppose I don't 
want one? There is no option for that. Perhaps you can use option 0 for 
some of these, and that might help solve the indexing problem.)

-- 
Bartc

[toc] | [prev] | [next] | [standalone]


#106001

FromRob Gaddi <rgaddi@highlandtechnology.invalid>
Date2016-03-29 21:19 +0000
Message-ID<nderg8$i83$1@dont-email.me>
In reply to#105999
okdk wrote:

> This is my code
> import random
> import time
>
> pizzatype = [3.50,4.20,5.20,5.80,5.60]
> drinktype = [0.90,0.80,0.90]
> topping = [0.50,0.50,0.50,0.50]
>
> def Total_cost_cal (pt ,dt ,t):
>     total = pt + dt + t
>     return total
>
> print ("Welcome to Pizza Shed!")
>
> order = raw_input ("\n\nPLEASE PRESS ENTER TO ORDER." )
>
> tablenum = input ("Enter table number from 1-25 \n ")
> while tablenum>25 or tablenum <=0:
>     tablenum = input ("Enter the correct table number, there are only 25 tables ")
>     
> #Pizza menu with prices
>
> print ("---------------------")
>
> print ("Let me help you with your order!")
>
> print ("---------------------")
>
> order = raw_input ("\n\nPLEASE PRESS ENTER TO SELECT YOUR PIZZA." )
>
> print ("Menu")
>
> print (
>     "1 = cheese and tomato: 3.50, "
>     "2 = ham and pineapple: 4.20, "
>     "3 = vegetarian: 5.20, "
>     "4 = meat feast: 5.80, "
>     "5 = seafood: 5.60 " )
>
> menu = input("Enter the type of pizza that you want to order from 1-5 \n")
> while menu>5 or menu <=0:
>     menu = input ("Enter the right number ")
> pizza_cost = pizzatype[menu]
>     
> print ("------------------")
>
> pizza_amount = input ("Enter the amount of Pizzas that you want to order ")
> while pizza_amount > 10 or pizza_amount <=0:
>     pizza_amount = input ("Maximum amount is 10, Please enter again ")
>
> print ("--------------------")
>
> #base
>
> print ("Base")
>
> print (
>     "1 = thin and crispy,"
>     "2 = traditional" )
>
> base = input ("Select a base from 1-2 \n")
> while base>2 or base<=0:
>     base = input ("There are only 2 types, Please enter again ")
>
> print ("-------------------")
>
> #extra toppings
>
> print ("Extra Toppings")
>
> toppings = input ("Enter a number for your choice of extra topping \n Enter 1 for extra cheese \n Enter 2 for extra pepperoni \n Enter 3 for extra pineapple \n Enter 4 for extra peppers \n" )
> while toppings >4 or toppings < 0:
>     toppings = input ("There are only 4 types of extra toppings, Please try again " )
> topping_cost = topping[toppings]
>
> print ("-------------------------")
>
> #drink
>
> print ("Drink")
>
> print (
>     "1 = Cola: 0.90, "
>     "2 = Lemonande: 0.80, "
>     "3 = Fizzy Orange: 0.90 "
>     )
>
> drink = input ("Enter a number for your choice of drinks " )
> while drink>3 or drink<0:
>     drink = input ("Choices start from 0 to 3 " )
> drink_cost = drinktype[drink]
> drink_amount = input ("Enter the amount of drinks")
> while drink_amount >10 or drink_amount<0:
>     drink_amount = input (" You can only have upto 10 drinks, Please try again")
>     
>
> print ("--------------------------------")
>
> pizzatotal = pizza_cost*pizza_amount
> drinktotal = drink_cost*drink_amount
>
> total_cost = total_cost_cal(pizzatotal, drinktotal, topping_cost)
>
> print ("--------------------------------")
> print ("Calculating bill")
> print ("--------------------------------")
> print ("--------------------------------")
>
> print ("Thank You for ordering at Pizza Shed! ")
>
>
> Howeve, it doesnt seem to be working. It doesnt calculate the bill. I dont know what to do, as I'm less than average at this.
> it comes up as IndexError: list index out of range at line42
>
> Please help

Don't know which one is line 42; but I'd bet your problem is there.
As a rough guess, it might be the line that says:
  pizza_cost = pizzatype[menu]

You're bounding that to the range 1-5.  A Python list of length 5 has
indices 0-4.

But the error message is telling you everything you need to know; you're
trying to get a list index that's out of range in line 42. Find line
42, figure out what index you're asking it for, and you'll have your
answer. If you don't have an editor that shows you line numbers then
your editor is fundamentally terrible and you should not use it (I
personally like Notepad++ for Windows or Geany for Linux).

-- 
Rob Gaddi, Highland Technology -- www.highlandtechnology.com

Email address domain is currently out of order.  See above to fix.

[toc] | [prev] | [next] | [standalone]


#106015

FromWildman <best_lay@yahoo.com>
Date2016-03-29 17:51 -0500
Message-ID<MoCdnSzyu6GbmmbLnZ2dnUU7-bWdnZ2d@giganews.com>
In reply to#106001
On Tue, 29 Mar 2016 21:19:05 +0000, Rob Gaddi wrote:

>> menu = input("Enter the type of pizza that you want to order from 1-5 \n")
>> while menu>5 or menu <=0:
>>     menu = input ("Enter the right number ")
>> pizza_cost = pizzatype[menu]

As it has already been pointed out, a Python list starts with an index
of 0.  Change the last line in the above code to this...

    pizza_cost = pizzatype[menu - 1]

Anywhere else that your code references a list index you may need to
make the same change.

-- 
<Wildman> GNU/Linux user #557453
May the Source be with you.

[toc] | [prev] | [next] | [standalone]


#106003

FromYum Di <nevinadias3@gmail.com>
Date2016-03-29 14:32 -0700
Message-ID<ffd075d6-e1fc-446d-9bae-03d630cec55a@googlegroups.com>
In reply to#105999
import random
import time

pizzatype = [3.50,4.20,5.20,5.80,5.60]
drinktype = [0.90,0.80,0.90]
topping = [0.50,0.50,0.50,0.50]

def Total_cost_cal (pt ,dt ,t):
    total = pt + dt + t
    return total

print ("Welcome to Pizza Shed!")

order = raw_input ("\n\nPLEASE PRESS ENTER TO ORDER." )

tablenum = input ("Enter table number from 1-25 \n ")
while tablenum>25 or tablenum <=0:
    tablenum = input ("Enter the correct table number, there are only 25 tables ")
    
#Pizza menu with prices

print ("---------------------")

print ("Let me help you with your order!")

print ("---------------------")

order = raw_input ("\n\nPLEASE PRESS ENTER TO SELECT YOUR PIZZA." )

print ("Menu")

print (
    "1 = cheese and tomato: 3.50, "
    "2 = ham and pineapple: 4.20, "
    "3 = vegetarian: 5.20, "
    "4 = meat feast: 5.80, "
    "5 = seafood: 5.60 " )

menu = input("Enter the type of pizza that you want to order from 1-5 \n")
while menu>5 or menu <=1:
    menu = input ("Enter the right number ")
pizza_cost = pizzatype[menu]
    
print ("------------------")

pizza_amount = input ("Enter the amount of Pizzas that you want to order ")
while pizza_amount > 10 or pizza_amount <=0:
    pizza_amount = input ("Maximum amount is 10, Please enter again ")

print ("--------------------")

#base

print ("Base")

print (
    "1 = thin and crispy,"
    "2 = traditional" )

base = input ("Select a base from 1-2 \n")
while base>2 or base<=1:
    base = input ("There are only 2 types, Please enter again ")

if base_type == 1:
    print "You have chosen thin and crispy"
elif base_type == 2:
    print ("You have chosen traditional")
    
print ("-------------------")

#extra toppings

print ("Extra Toppings")

toppings = input ("Enter a number for your choice of extra topping \n Enter 1 for extra cheese \n Enter 2 for extra pepperoni \n Enter 3 for extra pineapple \n Enter 4 for extra peppers \n" )
while toppings >4 or toppings < 0:
    toppings = input ("There are only 4 types of extra toppings, Please try again " )
topping_cost = topping[toppings]

print ("-------------------------")

#drink

print ("Drink")

print (
    "1 = Cola: 0.90, "
    "2 = Lemonande: 0.80, "
    "3 = Fizzy Orange: 0.90 "
    )

drink = input ("Enter a number for your choice of drinks " )
while drink>3 or drink<0:
    drink = input ("Choices start from 0 to 3 " )
drink_cost = drinktype[drink]
drink_amount = input ("Enter the amount of drinks")
while drink_amount >10 or drink_amount<1:
    drink_amount = input (" You can only have upto 10 drinks, Please try again")
    

print ("--------------------------------")

pizzatotal = pizza_cost*pizza_amount
drinktotal = drink_cost*drink_amount

total_cost = total_cost_cal(pizzatotal, drinktotal, topping_cost)

print ("--------------------------------")
print ("Calculating bill")
print ("--------------------------------")
print ("--------------------------------")

print ("Thank You for ordering at Pizza Shed! ")

I still don't get it.. Sorry, I'm still quite new to this
I've have made few minor changes, but it still doesn't work

[toc] | [prev] | [next] | [standalone]


#106005

FromRob Gaddi <rgaddi@highlandtechnology.invalid>
Date2016-03-29 21:37 +0000
Message-ID<ndesjd$mr5$1@dont-email.me>
In reply to#106003
Yum Di wrote:

> I still don't get it.. Sorry, I'm still quite new to this
> I've have made few minor changes, but it still doesn't work

Then try entering one line at a time of your program into the
interactive interpreter.  Copy and paste is fine, but use the
interpreter to look at the actual values of variables that you're
creating.

Also, as a mailing list/Usenet etiquette note: You get to have one name
you go by.  Going around changing the name you're posting under in the
middle of the thread is a guaranteed way to piss folks off.  You didn't
know.  You now do.

-- 
Rob Gaddi, Highland Technology -- www.highlandtechnology.com

Email address domain is currently out of order.  See above to fix.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web