Skip to content

Commit 021e962

Browse files
authored
Merge pull request #50 from PdxCodeGuild/matt-lab04-blackjack
Matt lab04 blackjack
2 parents cfe437b + b9625ed commit 021e962

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed

code/matt/python/lab04.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#Matt Nichols
2+
#Lab04
3+
4+
#Version 1
5+
6+
#Choices to pull from
7+
cards = {
8+
"a": 1,
9+
"2": 2,
10+
"3": 3,
11+
"4": 4,
12+
"5": 5,
13+
"6": 6,
14+
"7": 7,
15+
"8": 8,
16+
"9": 9,
17+
"10": 10,
18+
"j": 10,
19+
"q": 10,
20+
"k": 10
21+
}
22+
23+
#While loop so the user can continue to put numbers unless they feel like exiting
24+
while True:
25+
#Try and except block starting from the beginning to the end, so if they make an input error no matter where, it goes back to the top
26+
try:
27+
#Sequence of asking for the players hand starting with card one. ALSO, giving them a outing if they decide to exit
28+
card_one = input("What's your first card?\nYour options are (A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, or K)\nType 'done' to exit\n").lower()
29+
if card_one == 'done':
30+
print("goodbye")
31+
break
32+
33+
value_of_card_one = cards[card_one]
34+
print(value_of_card_one)
35+
36+
#card 2
37+
card_two = input("What's your second card?\nYour options are (A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, or K)\nType 'done' to exit\n").lower()
38+
if card_two == 'done':
39+
print('goodbye')
40+
break
41+
42+
value_of_card_two = cards[card_two]
43+
print(value_of_card_two)
44+
45+
#card 3
46+
card_three = input("What's your third card?\nYour options are (A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, or K)\nType 'done' to exit\n").lower()
47+
if card_three == 'done':
48+
print('Goodbye')
49+
break
50+
51+
value_of_card_three = cards[card_three]
52+
print(value_of_card_three)
53+
54+
#Taking their cards and getting the total
55+
value_of_first_three_cards = value_of_card_one + value_of_card_two + value_of_card_three
56+
57+
#If statement for what recommendation I should apply
58+
if value_of_first_three_cards < 17:
59+
print(f"Your total is: {value_of_first_three_cards}. I'd advise that you hit")
60+
elif value_of_first_three_cards >= 17 and value_of_first_three_cards < 21:
61+
print(f"Your total is: {value_of_first_three_cards}. I'd advise that you stay")
62+
elif value_of_first_three_cards == 21:
63+
print(f"Your total is: {value_of_first_three_cards}!!! Nice, that's blackjack")
64+
elif value_of_first_three_cards > 21:
65+
print(f"Your total is: {value_of_first_three_cards}... Sorry, you busted")
66+
67+
except:
68+
print("That input did not go along with the choices that were presented\nEnsure that you put the options that are shown\n...............................................................")

code/matt/python/lab05.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'''Lab 5: Pick6
2+
3+
Have the computer play pick6 many times and determine net balance.
4+
5+
Initially the program will pick 6 random numbers as the 'winner'. Then try playing pick6 100,000 times, with the ticket cost and payoff below.
6+
7+
A ticket contains 6 numbers, 1 to 99, and the number of matches between the ticket and the winning numbers determines the payoff.
8+
Order matters, if the winning numbers are [5, 10] and your ticket numbers are [10, 5] you have 0 matches.
9+
If the winning numbers are [5, 10, 2] and your ticket numbers are [10, 5, 2], you have 1 match. Calculate your net winnings (the sum of all expenses and earnings).
10+
11+
a ticket costs $2
12+
if 1 number matches, you win $4
13+
if 2 numbers match, you win $7
14+
if 3 numbers match, you win $100
15+
if 4 numbers match, you win $50,000
16+
if 5 numbers match, you win $1,000,000
17+
if 6 numbers match, you win $25,000,000
18+
19+
One function you might write is pick6() which will generate a list of 6 random numbers, which can then be used for both the winning numbers and tickets.
20+
Another function could be num_matches(winning, ticket) which returns the number of matches between the winning numbers and the ticket.
21+
Steps
22+
23+
Generate a list of 6 random numbers representing the winning tickets
24+
Start your balance at 0
25+
Loop 100,000 times, for each loop:
26+
Generate a list of 6 random numbers representing the ticket
27+
Subtract 2 from your balance (you bought a ticket)
28+
Find how many numbers match
29+
Add to your balance the winnings from your matches
30+
After the loop, print the final balance'''
31+
import random
32+
#print(random.randint(1,99)) - gives random number 1-99 as expected
33+
def winning_numbers():
34+
nums = []
35+
while len(nums) < 7:
36+
nums.append(random.randint(1, 99))
37+
print(nums)
38+
lottery = []
39+
print(winning_numbers(lottery))
40+

0 commit comments

Comments
 (0)