-5

I'm new to python and can't figure out why my code is throwing out this error. I'm trying to use c to compare the two lists.

def playPowerball():
    powerball = []
    choices = []
    c = []
    while len(powerball) < 6:
        number = random.randint(1,64)
        if number not in powerball:
            powerball.append(number)
    while len(choices) < 6:
        pick = int(raw_input('Pick a number between 1 and 64: '))
        if pick not in choices:
            choices.append(pick)
    for i in powerball:
        for i in choices:
            c += 1
    print ('You have',c,'correct',powerball,choices)

Error:

U:\Python\Lottery Ticket.py in playPowerball()
     15             choices.append(pick)
     16     for i in powerball:
---> 17         if i in choices:
     18             c += 1
     19     print ('You have',c,'correct',powerball,choices)

TypeError: argument of type 'int' is not iterable 

Edit: I did mean choices instead of pick, yet the code still doesn't work.

Edit 2: Thank you, sKwa, that solved my issue!

  • `pick` is an int, you cannot iterate through it. Do you mean `for i in choices` instead of `for i in pick`? – user3483203 Jan 08 '18 at 14:30
  • what are you trying to do? `pick` is an integer, and then you're attempting to iterate over some `i` in it, which is not possible, because `pick` is of type `int` – Zinki Jan 08 '18 at 14:30
  • 1
    Your code is not the same as the error. – JBernardo Jan 08 '18 at 14:30
  • 3
    Possible duplicate of [How do I fix TypeError: 'int' object is not iterable?](https://stackoverflow.com/questions/14941288/how-do-i-fix-typeerror-int-object-is-not-iterable) – gonczor Jan 08 '18 at 14:32
  • 1
    I not sure, but try `if i == pick` instead of `if i in pick`, because `pick` is `int` and not iterable object. – sKwa Jan 08 '18 at 14:33

2 Answers2

0

The error is pretty clear : pick is an int. The syntax for i in *someInt* is not a valid syntax in python.

Because you wrote this line :

   pick = int(raw_input('Pick a number between 1 and 64: '))

Then, you use .... in pick .

Just imagine pick value is 5 .

What should for i in 5 or if i in 5 actually do ?

Pac0
  • 21,465
  • 8
  • 65
  • 74
-1

You are trying to iterate over an integer which isn't valid. Your issue is here: You have assigned pick the data type 'Integer' but try to iterate over it as if it's a list.

 for i in powerball:
        for i in pick:
            c += 1

 for i in powerball:
---> 17         if i in pick:
     18             c += 1

I presume you wish to check if the picked number is in the powerball?

You'd change line 17 to:

if pick == i