Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:not': 0.03; 'tutorial': 0.03; 'else:': 0.03; 'elif': 0.05; 'python)': 0.05; 'indices': 0.07; 'string': 0.09; 'lookup': 0.09; 'violates': 0.09; 'python': 0.11; 'cheers': 0.12; '<>.': 0.14; 'random': 0.14; "(i'm": 0.16; '(just': 0.16; 'email addr:hotmail.com>': 0.16; 'fetch': 0.16; 'incorrect': 0.16; 'integers,': 0.16; 'integers.': 0.16; 'pep8': 0.16; 'skip:p 120': 0.16; 'tuple': 0.16; 'typeerror:': 0.16; 'url:pep-0008': 0.16; 'url:peps': 0.16; 'student': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'variable': 0.18; 'trying': 0.19; 'feb': 0.22; 'import': 0.22; 'print': 0.22; 'error': 0.23; "aren't": 0.24; 'finally,': 0.24; 'tue': 0.24; 'url:dev': 0.24; 'first,': 0.26; 'values': 0.27; 'to:2**1': 0.27; 'skip:p 30': 0.29; 'points': 0.29; 'to:no real name:2**1': 0.29; 'subject:list': 0.30; 'message-id:@mail.gmail.com': 0.30; 'skip:( 20': 0.30; 'url:mailman': 0.30; 'code': 0.31; "skip:' 10": 0.31; 'second,': 0.31; 'tuples': 0.31; 'lists': 0.32; 'probably': 0.32; 'skip:c 30': 0.32; 'url:python': 0.33; 'style': 0.33; 'received:209.85': 0.35; 'received:google.com': 0.35; 'there': 0.35; '8bit%:9': 0.36; 'url:listinfo': 0.36; 'hi,': 0.36; 'url:org': 0.36; 'list': 0.37; 'received:209': 0.37; 'skip:& 10': 0.38; 'lists.': 0.38; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'url:mail': 0.40; 'how': 0.40; 'url:3': 0.61; 'first': 0.61; 'worth': 0.66; 'url:4': 0.69; 'capital': 0.73; '2015': 0.84; 'to:addr:hotmail.com': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:from:date:message-id:subject:to :content-type; bh=9W06OGV998+Zh5twdKxp8zLOH6Jdg3V3wBx9+FeP+/4=; b=lCjwUc295XnwrF+UD9mvOfBXoZ+UGd4+hyJf3RySx1WR6ioKzccLd1IcYHbiKL9Z7I XYlj18qTyCao/BkhJh4F+d6mReBOahtbxLgLCV9g1KnGz6rhreB/ASCnbTcVEJcfFA8J OmVGPJfeCivCXWXUT16KWRSqAhVQjmtUfa/u9psmU2CfqscBBa9bRdAhumWOTp18o7zW DPOdiEgnW3sXkDONhhv0nH4k+HXCk69Gz5wfKPmaTQ643qqw1Tg8qsUdD5gfjwDxN6LT C9+7bmoQ/a8zokHDXwJ7mapeB/RZDIixhvJ1hblWcS+iidFDFOaaEOAwpZD+9Rb6m8CT NbgA== X-Received: by 10.70.88.79 with SMTP id be15mr33097187pdb.126.1423526754488; Mon, 09 Feb 2015 16:05:54 -0800 (PST) MIME-Version: 1.0 References: From: Ryan Stuart Date: Tue, 10 Feb 2015 00:05:54 +0000 Subject: Re: TypeError: list indices must be integers, not tuple To: james8booker@hotmail.com, python-list@python.org Content-Type: multipart/alternative; boundary=e89a8ff1c24e87992a050eb0a60b X-Mailman-Approved-At: Tue, 10 Feb 2015 09:01:51 +0100 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 124 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1423555312 news.xs4all.nl 2912 [2001:888:2000:d::a6]:54770 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:85433 --e89a8ff1c24e87992a050eb0a60b Content-Type: text/plain; charset=UTF-8 Hi, There is a lot of issues with this code. First, setting fav to a 1 tuples with a string probably isn't what you want. What you probably mean is: if restraunt == ("Pizza"): fav = 1 Second, when you are trying to lookup items in Menu, you are using the incorrect fav. Lists have int indicies (just like the error points out). Values like ("1") aren't integers. Thirdly, Menu is a list of lists. To fetch "Barbeque pizza" from Menu, you need to do Menu[0][0], not Menu[0, 0]. Finally, Python comes with a style guide which you can find in pep8 . Your code violates that guide in many places. It might be worth working through the Python Tutorial . Cheers On Tue Feb 10 2015 at 9:55:40 AM 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) > -- > https://mail.python.org/mailman/listinfo/python-list > --e89a8ff1c24e87992a050eb0a60b Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi,

There is a lot of issues with this code. F= irst, setting fav to a 1 tuples with a string probably isn't what you w= ant. What you probably mean is:

if restraunt =3D= =3D ("Pizza"):
=C2=A0 =C2=A0 fav =3D 1

Second, when you are trying to lookup items in Men= u, you are using the incorrect fav. Lists have int indicies (just like the= =C2=A0error=C2=A0points out). Values like ("1") aren'= t=C2=A0integers.

Thirdly, Menu is = a list of lists. To fetch "Barbeque pizza" from Menu, you need to= do Menu[0][0], not Menu[0, 0].=C2=A0

Finally, Python comes with a style guide which you can find in pep8. Your code violates= that guide in many places. It might be worth working through the Python Tutorial.

Cheers

On Tue Feb 10 2015 at 9:55:40 AM <james8booker@hotmail.com> wrote:
import random
RandomNum =3D random.randint(0,7)
restraunt =3D raw_input("What's your favourite takeaway?Pizza, Chi= nease or Indian?")
if restraunt =3D=3D ("Pizza"):
=C2=A0 =C2=A0 fav =3D ("1")

elif restraunt =3D=3D ("Chinease"):
=C2=A0 =C2=A0 fav =3D ("2")

elif restraunt =3D=3D ("Indian"):
=C2=A0 =C2=A0 fav =3D ("3")

else:
=C2=A0 =C2=A0 print("Try using a capital letter, eg; 'Chinease'= ;")

Menu =3D [["Barbeque pizza","Peparoni","Hawain&quo= t;],["Curry","Noodles","Rice"],["= Tika Masala","Special Rice","Onion Bargees"= ]]

print Menu[fav,RandomNum]
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0^
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)
--
https://mail.python.org/mailman/listinfo/python-list
--e89a8ff1c24e87992a050eb0a60b--