Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3a.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; 'else:': 0.03; 'elif': 0.05; 'python)': 0.05; 'finally:': 0.07; 'indices': 0.07; 'skip:` 10': 0.07; 'skip:p 60': 0.07; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; '~ethan~': 0.09; 'random': 0.14; "(i'm": 0.16; 'filename:fname piece:signature': 0.16; 'integers,': 0.16; 'tuple': 0.16; 'tuple.': 0.16; 'typeerror:': 0.16; 'student': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'import': 0.22; 'portion': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'skip:` 20': 0.24; 'header:In- Reply-To:1': 0.27; 'subject:list': 0.30; 'should': 0.36; 'list': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'received:173': 0.61; 'first': 0.61; 'capital': 0.73; 'email addr:hotmail.com': 0.89 Date: Mon, 09 Feb 2015 16:02:31 -0800 From: Ethan Furman User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: TypeError: list indices must be integers, not tuple References: In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="rsQwao1AQ3bkhw3T8jwPVfoVuH16q8SiL" 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: 76 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1423526589 news.xs4all.nl 2972 [2001:888:2000:d::a6]:53955 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:85413 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --rsQwao1AQ3bkhw3T8jwPVfoVuH16q8SiL Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 02/09/2015 03:52 PM, james8booker@hotmail.com wrote: > import random > RandomNum =3D random.randint(0,7) > restraunt =3D raw_input("What's your favourite takeaway?Pizza, Chinease= or Indian?") > if restraunt =3D=3D ("Pizza"): > fav =3D ("1") >=20 > elif restraunt =3D=3D ("Chinease"): > fav =3D ("2") =20 >=20 > elif restraunt =3D=3D ("Indian"): > fav =3D ("3") > =20 > else: > print("Try using a capital letter, eg; 'Chinease'") > =20 > Menu =3D [["Barbeque pizza","Peparoni","Hawain"],["Curry","Noodles","Ri= ce"],["Tika Masala","Special Rice","Onion Bargees"]] >=20 > print Menu[fav,RandomNum] > ^ > TypeError: list indices must be integers, not tuple >=20 > 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)=20 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 =3D Menu[fav] random_food =3D submenu[RandomNum] -- ~Ethan~ --rsQwao1AQ3bkhw3T8jwPVfoVuH16q8SiL Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iQIcBAEBAgAGBQJU2UqaAAoJENZ7D1rrH75NdjQP/1b8n3JlPKn1YbEz7rnAYVNr X7CVCR77SjJBwXEE9hjaQbt4IrSgzm6thyKmndyZqFdhy9RoHWlGVwwWjpfUhCK8 cJJDgFSZnaTH9kHvPIbf5gle+r38grEWGklsJgMV+VYcr7PKk54egOH9MiKYpjsP lia57XHtuqVnFHKIQo8d0j4iXTjlDBek4hquNp0xYxS+Ic7ANcx64v4H8NYJnOpC LeQqIstv8i8rljc/m5qZcc5O0YyryBuw2GxsitE9Kodb5NQunCxJBRT8lxQ+EuNt YluLXXfXO3o7DnJnhAjE18U8u9oAPbBWVNnMpf20Yeg1BS0lM6ENGXc3S2xEAgi2 hnMkZ5esjCAcOWKAkpsF1t9LosNJsuPchibB5DqSKhkdC1hWo9JjRLrbkN2cOg6C iJl5wqepok1ZTHkv+pXRcyBcqj8V99i6eQ+eyxWTTt1xMHDqyhOVQYPauqwY8JPO if9oSqZWS1mr0nTu2nY/DZpn12ggbfluH9bv0ys7YlR4T5DIuy20luVeY6LBs6Zl PLPVsneFKRGPBj5IR9RwUA17Wk9WHciyO5AzLj8s+vNgUlSJDAQ3cLkc9AB3GDcD 31LEYSmVSBoVG8uG/m0at/GvL+W7qXx6XBRrQPWef31/NpfCbqBlgim5I/l6PGRv PDTwSTAc1MnFARqJe8LB =6Sp0 -----END PGP SIGNATURE----- --rsQwao1AQ3bkhw3T8jwPVfoVuH16q8SiL--