I was trying to make a lottery generating machine that checks how many tries it takes to get that winning ticket
from random import choice
pack = (1,2,3,4,5,6,7,8,9,10,'a','b','c','d','e')
my_ticket=[]
times = -1
robot_ticket = []
while len(robot_ticket) < 5:
robo = choice(pack)
robot_ticket.append(robo)
continue
while robot_ticket == my_ticket:
if robot_ticket not in my_ticket:
times=times 1
my_ticket.clear()
while len(my_ticket) < 5:
robo = choice(pack)
my_ticket.append(robo)
elif robot_ticket in my_ticket:
print(f"total nuber of tries: {times}")
this program was the task of eric matthens book ie, 9.15
CodePudding user response:
while robot_ticket == my_ticket
This condition will never be true because my_ticket is an empty array and it is getting compared with robot_ticket which has 5 random values.
CodePudding user response:
Code:-
from random import choice
pack = (1,2,3,4,5,6,7,8,9,10,'a','b','c','d','e')
my_ticket=[]
times = -1
robot_ticket = []
while len(robot_ticket) < 5:
robo = choice(pack)
robot_ticket.append(robo)
myticket=choice(pack)
my_ticket.append(myticket)
while robot_ticket != my_ticket:
times=times 1
my_ticket.clear()
while len(my_ticket) < 5:
myticket=choice(pack)
my_ticket.append(myticket)
print(f"Total nuber of tries: {times}")
Output:-
Total nuber of tries: 25022