Hi, I’m trying to build a simple lotto lottery game. When a number picked by a user (from ticket_input) matches one of the randomly produced values (ticket_lottery), the player gets 1 point.
Now, I’m using only values from 0 to 9 as the code doesn’t work as expected in all steps.
I’m struggling with incrementing a value (points) as it engages the loop and conditional statements. The operation +=1 always refers to the value of points equals 0, so the total sum of points is wrong.
I’d be grateful for any help.
import random
ticket_lottery = random.sample(range(0, 9), k=7)
print("Provide 7 numbers from 0 to 9 (one by one- separated by spacebars):")
ticket_input = list(map(int, input().split()))
tl = sorted(ticket_lottery)
ti = sorted(ticket_input)
for item in ti:
points = 0
if ((item <= len(ti)) and (item in tl)):
points += 1
print("Item: {}, Lotto:{}, Points:{}".format(item, tl, points))
elif((item <= len(ti)) and (item not in tl)):
item += 1
continue
else:
break
print("You got {} points in total".format(points))