5 Replies - 619 Views - Last Post: 30 March 2016 - 10:38 AM Rate Topic: -----

#1 nbear  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 29-March 16

comes up as IndexError: list index out of range

Posted 29 March 2016 - 02:12 PM

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! ")




This is my code, which I've have made.
However, it doesnt seem to be working, after I tried to calculate the bill.
In line 42, it comes up as IndexError: list index out of range.
I m not sure what to do, as I m less than average at this.

Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: comes up as IndexError: list index out of range

#2 andrewsw  Icon User is online

  • say what now
  • member icon

Reputation: 6409
  • View blog
  • Posts: 25,903
  • Joined: 12-December 12

Re: comes up as IndexError: list index out of range

Posted 29 March 2016 - 02:14 PM

Please use a meaningful title, not "Help with Code!". I have changed it for you.
Was This Post Helpful? 0
  • +
  • -

#3 nbear  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 29-March 16

Re: comes up as IndexError: list index out of range

Posted 29 March 2016 - 02:16 PM

Sorry, I am new at this..
Thanks though
Was This Post Helpful? 0
  • +
  • -

#4 CurlyJoe  Icon User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 96
  • Joined: 19-September 13

Re: comes up as IndexError: list index out of range

Posted 29 March 2016 - 05:33 PM

The problem here is that you have 100+ lines of code, and apparently have done no testing. This line
while menu>5 or menu <=0:
allows for entries of 1-->5, while pizzatypes is a list and uses offsets, 0-->4 (use a print statement to see when the error occurs). For better assistance, next time include the complete error message so we don't have to guess where line 42 is. as you may or may not have a shebang as the first line which would push everything down, or many other things.

This post has been edited by CurlyJoe: 29 March 2016 - 05:39 PM

Was This Post Helpful? 0
  • +
  • -

#5 ndc85430  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 613
  • View blog
  • Posts: 2,586
  • Joined: 13-June 14

Re: comes up as IndexError: list index out of range

Posted 29 March 2016 - 10:31 PM

input() returns a string, not an int.
Was This Post Helpful? 0
  • +
  • -

#6 CurlyJoe  Icon User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 96
  • Joined: 19-September 13

Re: comes up as IndexError: list index out of range

Posted 30 March 2016 - 10:38 AM

View Postndc85430, on 29 March 2016 - 10:31 PM, said:

input() returns a string, not an int.
While that is true for Python-3X it shows a different error, something like list indices must be an int not a str, so it's a safe assumption that the OP is on Python-2X. Yes it can be confusing, so stick to learning Python-3x as it is the future, and don't worry about the rest.

This post has been edited by CurlyJoe: 30 March 2016 - 10:40 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1