On 02/09/2015 03:52 PM, james8boo...@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")
> 
> 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) 

When you say

 Menu[fav,RandomNum]

the `fav,RandomNum` portion is a tuple.

`fav` should be 1 or 2 or 3, not "1" nor "2" nor "3".

`RandomNum` should be be `random.randint(0,2)`

Finally:

submenu = Menu[fav]

random_food = submenu[RandomNum]

--
~Ethan~

Attachment: signature.asc
Description: OpenPGP digital signature

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to