Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #85433
| 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 | <ryan.stuart.85@gmail.com> |
| 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 | <dcae1673-8fe1-4734-90ce-682b8d4e6063@googlegroups.com> |
| From | Ryan Stuart <ryan.stuart.85@gmail.com> |
| 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 <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.18600.1423555312.18130.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
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
<https://www.python.org/dev/peps/pep-0008/>. Your code violates that guide
in many places. It might be worth working through the Python Tutorial
<https://docs.python.org/3.4/tutorial/>.
Cheers
On Tue Feb 10 2015 at 9:55:40 AM <james8booker@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)
> --
> https://mail.python.org/mailman/listinfo/python-list
>
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
TypeError: list indices must be integers, not tuple james8booker@hotmail.com - 2015-02-09 15:52 -0800 Re: TypeError: list indices must be integers, not tuple Ethan Furman <ethan@stoneleaf.us> - 2015-02-09 16:02 -0800 Re: TypeError: list indices must be integers, not tuple Dave Angel <davea@davea.name> - 2015-02-09 22:05 -0500 Re: TypeError: list indices must be integers, not tuple Dave Angel <davea@davea.name> - 2015-02-09 23:48 -0500 Re: TypeError: list indices must be integers, not tuple Terry Reedy <tjreedy@udel.edu> - 2015-02-10 00:57 -0500 Re: TypeError: list indices must be integers, not tuple Ryan Stuart <ryan.stuart.85@gmail.com> - 2015-02-10 00:05 +0000 Re: TypeError: list indices must be integers, not tuple Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-02-10 11:35 +0000 Re: TypeError: list indices must be integers, not tuple Dave Angel <davea@davea.name> - 2015-02-10 09:28 -0500 Re: TypeError: list indices must be integers, not tuple Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-02-10 14:32 +0000 Re: TypeError: list indices must be integers, not tuple Chris Angelico <rosuav@gmail.com> - 2015-02-11 01:33 +1100 Re: TypeError: list indices must be integers, not tuple Dave Angel <davea@davea.name> - 2015-02-10 10:51 -0500 Re: TypeError: list indices must be integers, not tuple Chris Angelico <rosuav@gmail.com> - 2015-02-11 05:48 +1100 Re: TypeError: list indices must be integers, not tuple Dave Angel <davea@davea.name> - 2015-02-10 15:38 -0500
csiph-web