Ask your own question, for FREE!
Computer Science 20 Online
Vocaloid:

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)

Vocaloid:

`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)`

Vocaloid:

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)

Vocaloid:

Please do not comment unless you are familiar with python and are making a serious attempt to help.

Vocaloid:

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)

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Latest Questions
Breathless: Spooky witch but cute
3 hours ago 3 Replies 0 Medals
Arriyanalol: help
3 hours ago 10 Replies 2 Medals
Arriyanalol: @tinydinoUwU stop trying to find a argument u blad lil boy
1 day ago 5 Replies 3 Medals
Jaded012023: Please tell me what you all think of this song
6 hours ago 6 Replies 1 Medal
Arriyanalol: bro how
6 hours ago 2 Replies 3 Medals
Arriyanalol: cant wait for the new bluey movie in 2027
1 day ago 12 Replies 2 Medals
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!