randomgenerator() is a function that yields 6 random integers, the user is prompted to also enter 6 values which are added to lucky[]. I want to compare each yield value to the lucky[] list for a match, but the if condition is not being met.
for x in randomgenerator():
print(f"\n{x} is a winning number.")
if x in lucky:
print(f"There is a match with number {x}")
match.append(x)
def randomgenerator():
for i in range(5):
yield random.randint(1,2)
yield random.randint(1,2)
CodePudding user response:
You said randomgenerator
returns a tuple
containing int
s.
randomgenerator()
is a function that yields 6 random values
I guess by "values" you meant int
egers, since it's very strange to generate random str
ings.
Then lucky
is filled with input()
returned values, which are str
ings.
if str(x) in lucky: # This should work, since it will convert the int x to a string
a similar solution would be:
lucky = list(map(int, lucky)) # all the elements are converted to integers