python question. I'm trying to set up a program to generate a lottery ticket from a list of digits. I want the program to select 4 digits from the list *without* duplicates. how can I set up the logic properly? (my current code below)
`from random import * lotto_list = winning_ticket = [] for i in range(4): pick = choice(lotto_list) if pick not in winning_ticket: winning_ticket.append(choice(lotto_list)) winning_ticket.sort() print("If your ticket matches these numbers/letters, you win!") print(winning_ticket)`
sorry, it didn't paste over, but the lotto_list is a list of the digits 0-9 and the letters A-E (the exercise instructions specified 10 numbers and 5 letters)
Please do not comment unless you are familiar with python and are making a serious attempt to help.
ok nvm I got it, I changed the logic of the code to a while loop instead from random import * lotto_list = winning_ticket = [] while len(winning_ticket) < 4: pick = choice(lotto_list) if pick not in winning_ticket: winning_ticket.append(pick) winning_ticket.sort() print("If your ticket matches these numbers/letters, you win!") print(winning_ticket)
Join our real-time social learning platform and learn together with your friends!