Skip to content

Commit c0920b3

Browse files
committed
commit lab5.py
1 parent 36f2706 commit c0920b3

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

Code/chadL/Python/lab5.py

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Lab 5: Pick6
2+
import random
3+
"""
4+
5+
Steps
6+
Generate a list of 6 random numbers representing the winning tickets
7+
8+
Loop 100,000 times, for each loop:
9+
Generate a list of 6 random numbers representing the ticket
10+
Subtract 2 from your balance (you bought a ticket)
11+
Find how many numbers match
12+
Add to your balance the winnings from your matches
13+
After the loop, print the final balance
14+
Version 2---------------------------------------------------------
15+
The ROI (return on investment) is defined as (earnings - expenses)/expenses.
16+
Calculate your ROI, print it out along with your earnings and expenses.
17+
a ticket costs $2
18+
if 1 number matches, you win $4
19+
if 2 numbers match, you win $7
20+
if 3 numbers match, you win $100
21+
if 4 numbers match, you win $50,000
22+
if 5 numbers match, you win $1,000,000
23+
if 6 numbers match, you win $25,000,000
24+
25+
lottery_numbers = [] # storage holder for our 6 lucky numbers
26+
for i in range(0,6):
27+
number = random.randint(1,99)
28+
while number in lottery_numbers:
29+
number = random.randint(1,99)
30+
lottery_numbers.append(number)
31+
32+
counter = 0 #Start your balance at 0
33+
for number in lottery_numbers:
34+
if number in lottery_numbers:
35+
counter +=1
36+
37+
print(f" your lottery numbers are: {lottery_numbers}.")
38+
39+
wallet = 0
40+
"""
41+
42+
43+
44+
45+
46+
47+
48+
49+
50+
51+
winnings = 0
52+
expenses = 0
53+
matches = 0
54+
55+
winning_dict = {
56+
0: 0,
57+
1: 4,
58+
2: 7,
59+
3: 100,
60+
4: 50000,
61+
5: 100000,
62+
6: 250000
63+
}
64+
65+
def pick_six():
66+
num_list = [random.randint(0,99) for i in range(6)]
67+
return(num_list)
68+
69+
#winning_ticket = pick_six()
70+
71+
def ticket_bought(): #tracking expenses
72+
global expenses
73+
expenses += 2
74+
return pick_six()
75+
76+
#my_ticket = ticket_bought()
77+
#print(expenses) #alt +shift down key
78+
79+
def comparison_tool(winning_ticket, ticket):
80+
global matches
81+
for i, value in enumerate(ticket):
82+
if winning_ticket[i] == value:
83+
matches += 1
84+
return matches
85+
86+
def win_values(x):
87+
return winning_dict[x]
88+
89+
winning_ticket = pick_six() # resets match ticket
90+
for i in range(100000):
91+
my_ticket = ticket_bought()
92+
93+
winnings += win_values(comparison_tool(winning_ticket, my_ticket) )
94+
my_ticket =[]
95+
matches = 0
96+
97+
print(f"your wiinings are: {winnings}, and your expenses are: {expenses}")
98+
99+
100+

0 commit comments

Comments
 (0)