Home > OS >  Random Number Script Is not looping
Random Number Script Is not looping

Time:12-01

for y in (random.randint(0,9)) in (x): TypeError: argument of type 'int' is not iterable

import random
x = (random.randint(0,9))
print (x)
y = (random.randint(0,9))
print (y)
for y in (random.randint(0,9)) in (x):
    if (y)==(x):
        break

CodePudding user response:

what does (random.randint(0,9)) in (x) means?

You try iterate over int/number. You need to create an iterable object to loop over it like list, tuple, range etc.

CodePudding user response:

If you want to iterate until x==y you should use a while loop. for loops iterate over a sequence.
You could do something like

import random
x = (random.randint(0,9))
print (x)
y = (random.randint(0,9))
print (y)
while y != x:
    y = (random.randint(0,9))

In general do not put assignations inside conditions (we are not in C!)

  • Related