[Tutor] Newbie problems

Alan Gauld alan.gauld at btinternet.com
Sat May 2 09:58:34 CEST 2015


Please use ReplyAll to include everyone on the the list.


On 02/05/15 03:26, Jag Sherrington wrote:
> Hi Alan
> Thanks for your help. I followed your instruction and get the 
> following message:
>
> Enter a number between 0 and 36: 9
> Traceback (most recent call last):
> File "C:\Python34\Tests\Roulette_wheel_colours.py", line 8, in <module>
> if number in green_numbers:
> TypeError: argument of type 'int' is not iterable

Think about what I said rather than applying it blindly.

I said the red and black variables were both tuples and so needed an 
'in' test.
Can you see the logic of that. Why it needs to be 'in' rather than equality?

I made no mention of green because it is not a tuple.
Can you see why 'in' is not the right test for green. Can you see
why the interpreter is complaining?

Never change code randomly or just because somebody else says
so (or you think they said so). Always underdstand *why* you are doing it.


>
> *This is what I programmed:*
>
> number = int(input('Enter a number between 0 and 36: '))
> green_numbers = (0)
> red_numbers = (1, 3, 5, 7, 9, 12, 14, 16, 18, 19,\
>               21, 23, 25, 27, 30, 32, 34, 36)
> black_numbers = (2, 4, 6, 8, 10, 11, 13, 15, 17, 20,\
>                 22, 24, 26, 28, 34, 29, 31, 33, 35)
>
> if number in green_numbers:
>     print('Number is Green')
>
> elif number in red_numbers:
>     print('Number is Red')
>
> elif number in black_numbers:
>         print('Number is Black')
>
>

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list