Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #85441
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| 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; 'from:addr:yahoo.co.uk': 0.04; 'elif': 0.05; 'python)': 0.05; 'indices': 0.07; 'skip:p 60': 0.07; 'string': 0.09; 'lawrence': 0.09; 'lookup': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'violates': 0.09; 'python': 0.11; 'cheers': 0.12; '<>.': 0.14; 'language.': 0.14; 'random': 0.14; "(i'm": 0.16; '(just': 0.16; 'fetch': 0.16; 'happily': 0.16; 'incorrect': 0.16; 'integers,': 0.16; 'integers.': 0.16; 'pep8': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'stuart': 0.16; 'tuple': 0.16; 'typeerror:': 0.16; 'url:pep-0008': 0.16; 'url:peps': 0.16; 'student': 0.16; 'language': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'variable': 0.18; 'trying': 0.19; 'thanks.': 0.20; 'feb': 0.22; 'import': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; "aren't": 0.24; 'finally,': 0.24; 'tue': 0.24; 'url:dev': 0.24; 'first,': 0.26; 'post': 0.26; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'points': 0.29; 'subject:list': 0.30; 'url:mailman': 0.30; 'code': 0.31; 'second,': 0.31; 'tuples': 0.31; 'lists': 0.32; 'probably': 0.32; 'url:python': 0.33; 'style': 0.33; 'anywhere': 0.35; 'there': 0.35; 'ryan': 0.36; 'url:listinfo': 0.36; "i'll": 0.36; 'hi,': 0.36; 'url:org': 0.36; 'list': 0.37; 'lists.': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'url:mail': 0.40; 'how': 0.40; 'url:3': 0.61; 'first': 0.61; 'show': 0.63; 'our': 0.64; 'charset:windows-1252': 0.65; 'worth': 0.66; 'url:4': 0.69; 'capital': 0.73; '2015': 0.84; 'follow,': 0.84; 'choice.': 0.93 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
| Subject | Re: TypeError: list indices must be integers, not tuple |
| Date | Tue, 10 Feb 2015 11:35:23 +0000 |
| References | <dcae1673-8fe1-4734-90ce-682b8d4e6063@googlegroups.com> <CAM8kh5sJ4Hiu08pn5xcLP1SQm2rpy+dvtUZWU9LGaYQfh4RdFQ@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | host-92-24-222-48.ppp.as43234.net |
| User-Agent | Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 |
| In-Reply-To | <CAM8kh5sJ4Hiu08pn5xcLP1SQm2rpy+dvtUZWU9LGaYQfh4RdFQ@mail.gmail.com> |
| 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.18606.1423568173.18130.python-list@python.org> (permalink) |
| Lines | 70 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1423568173 news.xs4all.nl 2899 [2001:888:2000:d::a6]:42241 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:85441 |
Show key headers only | View raw
On 10/02/2015 00:05, Ryan Stuart wrote:
> 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
> <mailto: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
> <https://mail.python.org/mailman/listinfo/python-list>
>
If you can show me a one tuple anywhere in the original code I'll
happily buy you a tipple of your choice.
Also please don't top post here, it makes following long threads
difficult if not impossible to follow, thanks.
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
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