Help with python code

BartC bc at freeuk.com
Tue Mar 29 17:19:56 EDT 2016


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





More information about the Python-list mailing list