Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #85422
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <davea@davea.name> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.015 |
| X-Spam-Evidence | '*H*': 0.97; '*S*': 0.00; 'subject:not': 0.03; 'else:': 0.03; 'elif': 0.05; 'string.': 0.05; 'skip:p 60': 0.07; 'string': 0.09; 'typed': 0.09; 'random': 0.14; 'assignments': 0.16; 'clause.': 0.16; 'integer,': 0.16; 'index': 0.16; 'wrote:': 0.18; 'pointed': 0.19; 'import': 0.22; 'print': 0.22; 'header :User-Agent:1': 0.23; 'logical': 0.24; 'header:In-Reply-To:1': 0.27; 'possibility': 0.29; 'subject:list': 0.30; 'are.': 0.31; 'figure': 0.32; 'supposed': 0.32; 'raw': 0.33; "can't": 0.35; 'created': 0.35; 'something': 0.35; 'case,': 0.35; 'but': 0.35; 'add': 0.35; 'there': 0.35; 'whatever': 0.38; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'most': 0.60; "you've": 0.63; 'choose': 0.64; 'charset:windows-1252': 0.65; 'anything.': 0.68; 'received:74.208': 0.68; 'capital': 0.73; 'ethan': 0.84; 'furman': 0.84; 'guessed': 0.84; 'received:74.208.4.194': 0.84; 'email addr:hotmail.com': 0.89 |
| Date | Mon, 09 Feb 2015 22:05:11 -0500 |
| From | Dave Angel <davea@davea.name> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: TypeError: list indices must be integers, not tuple |
| References | <dcae1673-8fe1-4734-90ce-682b8d4e6063@googlegroups.com> <54D94A97.6040902@stoneleaf.us> |
| In-Reply-To | <54D94A97.6040902@stoneleaf.us> |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Provags-ID | V02:K0:up4C4IUiuNMjrgzSFmyyQjeY+d/7gARshqR+tjvd72v cHX7TcuQcvn/GxaV6o7exHTc48P3uw58/aTRl4r05+xFVQM9ai qQIPWvD+k91hCbk/A1jpjZ94YMT/Cb/PoH6bjabzAuddXnnbVH r0S0C3Bf3KRXpCdbsb1/+hE+Irr2KNn6K1QlN1brg5/IksWiac riEbds7/2McjsUi6aYhkX9euVAjia0tyCqfd60QY02umyyyOHP 3pMLkywT8li9fCDgV5WjOvME81BmUKWDgGvMpVGJ6IST7rBxrg 0Ue1Cuf5DpNL4RS84kVOd58yhFqz/hLaq77emGwhb6h7oko/Lm qj/1flDRSaY2jebschYU= |
| X-UI-Out-Filterresults | notjunk:1; |
| 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.18590.1423537534.18130.python-list@python.org> (permalink) |
| Lines | 49 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1423537534 news.xs4all.nl 2941 [2001:888:2000:d::a6]:55078 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:85422 |
Show key headers only | View raw
On 02/09/2015 07:02 PM, Ethan Furman wrote:
> On 02/09/2015 03:52 PM, 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'")
>>
So just what is RandomNum supposed to represent? You've selected it
from an interval of 0 to 7, but you don't have 8 of anything. The most
logical possibility I can figure is you want to use it instead of
whatever the user has typed into your raw input. Like in the else
clause. If that's the case, you'd want to add a
fav = RandomNum
line in the else clause.
Of course, as Ethan has pointed out, all the other assignments to fav
want to be integer, not string. You can't use a string to index a lis.
>> Menu = [["Barbeque pizza","Peparoni","Hawain"],["Curry","Noodles","Rice"],["Tika Masala","Special Rice","Onion Bargees"]]
>>
>> print Menu[fav,RandomNum]
Now that you've got a single value for fav, just say
print Menu[fav]
to print the submenu.
Now if Ethan has guessed right, that you wanted the random value to
choose from the submenu, then you would/should have created it after you
have the submenu, so you know how many possibilities there are.
Something like (untested):
RandomNum = random.randint(0, len(submenu)-1)
--
DaveA
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