[Tutor] Newbie problems

Dave Angel davea at davea.name
Sat May 2 12:13:13 CEST 2015


1) Please reply-list, or if your email program doesn't support that, do 
a reply-all.  The idea is to make sure tutor at python.org is in your To: 
field.  Otherwise you're just leaving private messages, and that's not 
what a public forum like this is about.

2) Please use text email, not html.  As you can see below, your 
formatting was thoroughly trashed by your email program.  I took a 
message at the html in your message, and you tried to use color as well, 
which won't be visible by most people here.

On 05/01/2015 10:29 PM, Jag Sherrington wrote:
> Hi DaveThanks for your help. I followed your instruction and got the following message:
> Enter a number between 0 and 36: 9Traceback (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
> 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')
> Kind regards, Jag BraveArt Multimedia
> 0421176576
>

Your remaining problem is that green_numbers isn't a list or tuple, it's 
just a single number.  You can change either of the following ways:

green_numbers = (0,)      #The comma forces it to be a tuple
or
green_numbers = [0]       #it's a list

Alternatively, you could use == for green, and in for the other two. 
But as good programming practice, it's good to keep symmetry for the 3 
cases.

-- 
DaveA



More information about the Tutor mailing list