TypeError: list indices must be integers, not tuple

Terry Reedy tjreedy at udel.edu
Tue Feb 10 00:57:05 EST 2015


On 2/9/2015 6:52 PM, james8booker at hotmail.com wrote:
> import random
> RandomNum = random.randint(0,7)
> restraunt = raw_input("What's your favourite takeaway?Pizza, Chinease or Indian?")
> if restraunt == ("Pizza"):
>      fav = ("1")

As a style note, putting parentheses around strings is worse than useless.

> elif restraunt == ("Chinease"):
>      fav = ("2")
>
> elif restraunt == ("Indian"):
>      fav = ("3")
>
> else:
>      print("Try using a capital letter, eg; 'Chinease'")
>
> Menu = [["Barbeque pizza","Peparoni","Hawain"],["Curry","Noodles","Rice"],["Tika Masala","Special Rice","Onion Bargees"]]
>
> print Menu[fav,RandomNum]
>                     ^
> TypeError: list indices must be integers, not tuple
>
> How do I set a variable to a random number then use it as a list indece, (I'm only a student in his first 6 months of using python)
>


-- 
Terry Jan Reedy




More information about the Python-list mailing list