Skip to content

Commit 06a9a4b

Browse files
committed
Merge branch 'main' of https://github.com/PdxCodeGuild/class_HB2 into kelin-lab04-blackjack-advice
2 parents 8f9c7bd + 6a00103 commit 06a9a4b

File tree

4 files changed

+151
-81
lines changed

4 files changed

+151
-81
lines changed

code/kaceyb/python/lab00/lab_00.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
21
# Lab 00: Average Numbers #
32

43
entering_numbers = True
54

65
list = []
76

87
while entering_numbers:
9-
8+
109
answer = input("Enter a number or 'done' to quit: ")
11-
12-
if answer == 'done':
10+
11+
if answer == "done":
1312
entering_numbers = False
14-
13+
1514
else:
1615
list.append(int(answer))
1716

18-
19-
print(f"\nYou entered nums {list} \n\nThe average of the numbers is {sum(list) / len(list)}")
20-
17+
18+
print(
19+
f"\nYou entered nums {list} \n\nThe average of the numbers is {sum(list) / len(list)}"
20+
)

code/kaceyb/python/lab02/lab_02.py

Lines changed: 42 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,17 @@
1-
2-
3-
41
# VERSION 1 #
52

63

4+
conversion_list = {"foot": 0.3048, "mile": 1609.34, "meter": 1, "kilometers": 1000}
75

8-
9-
10-
conversion_list = {
11-
'foot': 0.3048,
12-
'mile': 1609.34,
13-
'meter': 1,
14-
'kilometers': 1000
15-
16-
}
17-
18-
#
6+
#
197

208
# while True:
21-
9+
2210
# principle_unit = input("\nWhat is the distance in feet?: ")
2311
# total = (conversion_list['foot']) * int(principle_unit)
24-
12+
2513
# print(f"{principle_unit} feet is in {total} m")
26-
14+
2715
# break
2816

2917

@@ -46,21 +34,21 @@
4634

4735
# user = True
4836
# while user:
49-
37+
5038
# users_unit_input = input("\nWhat is the unit to convert to meters?: ")
51-
39+
5240
# users_unit_input == conversion_list[users_unit_input]
53-
41+
5442
# print(users_unit_input)
5543
# # print(users_distance_input)
5644
# users_distance_input = int(input("\nWhat is the distance to convert to meters?: "))
57-
45+
5846
# distance = users_distance_input * conversion_list[users_unit_input]
5947
# # print(distance)
6048
# print(f"{users_distance_input} {users_unit_input} is {((users_distance_input) * conversion_list[users_unit_input])} meters")
61-
49+
6250
# user = False
63-
51+
6452
# VERSION 3 #
6553

6654
# conversion_list = {
@@ -79,56 +67,55 @@
7967
# }
8068
# user = True
8169
# while user:
82-
70+
8371
# users_unit_input = input("\nWhat is the unit to convert to meters?: ")
84-
72+
8573
# users_unit_input == conversion_list[users_unit_input]
86-
74+
8775
# print(users_unit_input)
8876
# # print(users_distance_input)
8977
# users_distance_input = int(input("\nWhat is the distance to convert to meters?: "))
90-
78+
9179
# distance = users_distance_input * conversion_list[users_unit_input]
9280
# # print(distance)
9381
# print(f"{users_distance_input} {users_unit_input} is {((users_distance_input) * conversion_list[users_unit_input])} meters")
94-
82+
9583
# user = False
96-
97-
# VERSION 4 #
98-
99-
84+
85+
# VERSION 4 #
86+
87+
10088
conversion_list = {
101-
'foot': 0.3048,
102-
'feet': 0.3048,
103-
'mile': 1609.34,
104-
'miles': 1609.34,
105-
'meter': 1,
106-
'meters': 1,
107-
'kilometer': 1000,
108-
'kilometers': 1000,
109-
'yard': 0.9144,
110-
'yards': 0.9144,
111-
'inch': 0.0254,
112-
'inches': 0.0254
113-
}
89+
"foot": 0.3048,
90+
"feet": 0.3048,
91+
"mile": 1609.34,
92+
"miles": 1609.34,
93+
"meter": 1,
94+
"meters": 1,
95+
"kilometer": 1000,
96+
"kilometers": 1000,
97+
"yard": 0.9144,
98+
"yards": 0.9144,
99+
"inch": 0.0254,
100+
"inches": 0.0254,
101+
}
114102

115103
user = True
116-
while user:
104+
while user:
117105
users_distance_input = int(input("\nWhat is the distance to convert?: "))
118-
106+
119107
users_unit_input = input("\nWhat is the unit to convert from?: ")
120-
108+
121109
users_unit_input == conversion_list[users_unit_input]
122-
110+
123111
users_unit_output = input("\nWhat is the unit to convert to?: ")
124-
112+
125113
users_unit_output == conversion_list[users_unit_output]
126-
114+
127115
result = users_distance_input * conversion_list[users_unit_input]
128-
116+
129117
result = result / conversion_list[users_unit_output]
130-
118+
131119
print(f"{users_distance_input} {users_unit_input} is {result}")
132-
120+
133121
user = False
134-

code/kaceyb/python/lab03/lab_03.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# print(increment(5, 13))
1212

1313

14-
#results in Typeerror
14+
# results in Typeerror
1515
# def multiply(*nums):
1616
# total = 1
1717
# for n in nums:
@@ -23,7 +23,7 @@
2323

2424
# def repeat(quote, num):
2525
# print(quote * num)
26-
26+
2727
# print(repeat(f'\nLive your best life', 5))
2828

2929
# def get_temp(temp):
@@ -37,11 +37,8 @@
3737
# return 'Chilly'
3838
# else:
3939
# return 'Pack your parka'
40-
41-
# print(get_temp(40))
4240

43-
44-
from cmath import e
41+
# print(get_temp(40))
4542

4643

4744
number_words = {
@@ -73,8 +70,7 @@
7370
70: "seventy",
7471
80: "eighty",
7572
90: "ninety",
76-
100: "hundred"
77-
73+
100: "hundred",
7874
}
7975

8076
try:
@@ -84,33 +80,37 @@
8480
quit()
8581

8682

87-
88-
89-
tens_digit = number//10
90-
ones_digit = number%10
83+
tens_digit = number // 10
84+
ones_digit = number % 10
9185
ten_column = int(str(tens_digit) + "0")
9286

9387
# VERSION 2 #
94-
hundreds_digit = number//100
88+
hundreds_digit = number // 100
9589
hundreds_column = int(str(hundreds_digit) + "00")
96-
tens_column2 = int(str(tens_digit%10) + "0")
90+
tens_column2 = int(str(tens_digit % 10) + "0")
9791
tens_digit2 = tens_column2 + ones_digit
9892

9993
if number == 0:
10094
print("zero")
101-
95+
10296
elif hundreds_digit > 0:
10397
if ones_digit == 0 and tens_column2 == 0:
10498
print(number_words[hundreds_digit] + "-hundred")
10599
elif ones_digit == 0:
106100
print(number_words[hundreds_digit] + "-hundred-" + number_words[tens_column2])
107101
elif tens_column2 < 10:
108102
print(number_words[hundreds_digit] + "-hundred-" + number_words[ones_digit])
109-
elif tens_column2 <20:
103+
elif tens_column2 < 20:
110104
print(number_words[hundreds_digit] + "-hundred-" + number_words[tens_digit2])
111-
105+
112106
else:
113-
print(number_words[hundreds_digit] + "-hundred-" + number_words[tens_column2] + "-" + number_words[ones_digit])
107+
print(
108+
number_words[hundreds_digit]
109+
+ "-hundred-"
110+
+ number_words[tens_column2]
111+
+ "-"
112+
+ number_words[ones_digit]
113+
)
114114
elif ones_digit == 0:
115115
print(number_words[ten_column])
116116
elif number < 20:

code/kaceyb/python/lab04/lab_04.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Lab 4: Blackjack Advice
2+
3+
# Let's write a python program to give basic blackjack playing advice during a game by asking the player for cards.
4+
# First, ask the user for three playing cards (A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, or K).
5+
# Then, figure out the point value of each card individually. Number cards are worth their number, all face cards are worth 10.
6+
# At this point, assume aces are worth 1. Use the following rules to determine the advice:
7+
8+
# Less than 17, advise to "Hit"
9+
# Greater than or equal to 17, but less than 21, advise to "Stay"
10+
# Exactly 21, advise "Blackjack!"
11+
# Over 21, advise "Already Busted"
12+
13+
# Print out the current total point value and the advice.
14+
15+
# What's your first card? Q
16+
# What's your second card? 2
17+
# What's your third card? 3
18+
# 15 Hit
19+
20+
# What's your first card? K
21+
# What's your second card? 5
22+
# What's your third card? 5
23+
# 20 Stay
24+
25+
# What's your first card? Q
26+
# What's your second card? J
27+
# What's your third card? A
28+
# 21 Blackjack!
29+
30+
31+
# Then, figure out the point value of each card individually. Number cards are worth their number, all face cards are worth 10.
32+
player_cards = []
33+
34+
# First, ask the user for three playing cards (A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, or K).
35+
36+
for player_card in range(1, 4):
37+
player_cards.append(input(f"What's your card #{player_card}: ").upper())
38+
39+
# At this point, assume aces are worth 1. Use the following rules to determine the advice:
40+
41+
# Less than 17, advise to "Hit"
42+
# Greater than or equal to 17, but less than 21, advise to "Stay"
43+
# Exactly 21, advise "Blackjack!"
44+
# Over 21, advise "Already Busted"
45+
46+
47+
def summ(nums):
48+
total = 0
49+
cards = {
50+
"A": 1,
51+
"2": 2,
52+
"3": 3,
53+
"4": 4,
54+
"5": 5,
55+
"6": 6,
56+
"7": 7,
57+
"8": 8,
58+
"9": 9,
59+
"10": 10,
60+
"J": 10,
61+
"Q": 10,
62+
"K": 10,
63+
}
64+
65+
for num in nums:
66+
total = total + cards[num]
67+
return total
68+
69+
70+
cards_total = summ(player_cards)
71+
72+
if cards_total < 17:
73+
result = "Hit"
74+
elif cards_total >= 17 and cards_total < 21:
75+
result = "Stay"
76+
elif cards_total == 21:
77+
result = "Blackjack!"
78+
else:
79+
result = "Already Busted"
80+
81+
# Print out the current total point value and the advice.
82+
83+
print(f"{cards_total} is a {result}")

0 commit comments

Comments
 (0)