-
Notifications
You must be signed in to change notification settings - Fork 0
/
new_try_lottery.py
59 lines (42 loc) · 1.37 KB
/
new_try_lottery.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from random import choice
def get_winning_ticket(possibilities):
winning_ticket = []
#pulling a number out of the list until 4 have been pulled
while len(winning_ticket) < 4:
pulled_item = choice(possibilities)
#adding the number to the ticket
if pulled_item not in winning_ticket:
winning_ticket.append(pulled_item)
return winning_ticket
def get_your_ticket(possibilities):
your_ticket = []
while len(your_ticket) < 4:
pulled_item = choice(possibilities)
if pulled_item not in winning_ticket:
your_ticket.append(pulled_item)
return your_ticket
def checking_ticket(played_ticket, winning_ticket):
for element in played_ticket:
if element not in winning_ticket:
return False
return True
possibilities = [1, 2, 3, 4,5,6,7,8,9,10 , 'a', 'b', 'c', 'd', 'e']
winning_ticket = get_winning_ticket(possibilities)
won = False
plays = 0
max_tries = 10000
while not won:
new_ticket = get_your_ticket(possibilities)
won = checking_ticket(new_ticket, winning_ticket)
plays += 1
if plays >= max_tries:
break
if won:
print("We have a winning ticket!")
print(f"Your ticket: {new_ticket}")
print(f"Winning ticket: {winning_ticket}")
print(f"It only took {plays} tries to win!")
else:
print(f"Tried {plays} times, without pulling a winner. :(")
print(f"Your ticket: {new_ticket}")
print(f"Winning ticket: {winning_ticket}")