Skip to content

Commit 3ed3cc9

Browse files
committed
Merge branch 'main' of https://github.com/PdxCodeGuild/class_HB2 into kelin-lab04-blackjack-advice
2 parents 4a96e14 + 73e79cf commit 3ed3cc9

File tree

8 files changed

+466
-4
lines changed

8 files changed

+466
-4
lines changed

code/Andy/python/black_jack.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
jack = {
2+
'A': 1,
3+
'2' : 2,
4+
'3': 3,
5+
'4': 4,
6+
'5': 5,
7+
'6': 6,
8+
'7': 7,
9+
'8': 8,
10+
'9': 9,
11+
'10': 10,
12+
'J':10,
13+
'Q':10,
14+
'K': 10
15+
} #putting all cards in a dict to be able to pull from when i get further down
16+
17+
gambler = input('pick your first card from this selection A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, or K: ').upper()
18+
gambler2 = input('pick your second card from this selection A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, or K: ').upper() #.upper at the end of the input only works if YOU PUT THE PARENTHESIS!
19+
gambler3 = input('pick your third card from this selection A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, or K: ').upper()
20+
21+
# if gambler == 'a' or 'j' or 'q' or 'k':
22+
# gambler == gambler.upper #one way of having it become an uppercase above is the waaay easier way of doing that. that works for sure
23+
first = jack[gambler]
24+
25+
second = jack[gambler2]
26+
third = jack[gambler3] #first second and third are vaiables that call dictionary of jack and use the input of the gambler to get the the value of their selection
27+
28+
sum = first + second + third #the addition of all their values into one variable
29+
30+
31+
32+
if sum < 17: #if below 17
33+
print(f'your value is {sum}. Adise to Hit!')
34+
35+
elif sum in range (17 ,20):
36+
print(f'your value is {sum}. Advise to STAY!') #if between 17 and 20
37+
38+
elif sum == 21: #if equal to 21
39+
print('BLACKJACK!')
40+
41+
elif sum > 21:
42+
print('BUST!') #if statments if greater than 21
43+
44+
45+
46+
# print(gambler.upper()) #.upper doesnt work on the outside of the inputs but works in the print statment. and need open and closing parenthesis for it to work
47+
48+
49+
50+
51+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# # Version 1
2+
# nums = [5, 0, 8, 3, 4, 1, 6]
3+
4+
# total = 0
5+
6+
# for num in nums:
7+
# total = total + num
8+
9+
# average = total/(len(nums))
10+
# print(average)
11+
12+
13+
# for i in range(len(nums)):
14+
# print(nums[i])
15+
16+
# Version 2
17+
18+
19+
20+
nums = [] #place holder
21+
sum = 0 # place to help when adding the num together and help get the average
22+
23+
while True: #while statement to get all the numbers being put by the user
24+
user= input(' Please enter a number or done when finished: ')
25+
if user == 'done':
26+
break
27+
nums.append(int(user)) #strings dont add together for numbers, .append adding all the numbers in a list and the int making them into an integer.
28+
# print(nums)
29+
30+
for num in nums: #for statement helping me get the nums value of all the inputs and calling out single ones
31+
sum += num #where it calls the sigle ones and adds them together
32+
average = sum/ len(nums) #the len is getting the length of numbers so getting how many there is and the sum is getting the value of all the ones being put together and dividing them to get the average
33+
34+
print (f" Your total average is {round(average)} ") #round removes the decimal and has to be within the curly bracket to have the function work

code/jonpan/lab02.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,23 @@
2121
# 'yard': 0.9144,
2222
# 'inch': 0.0254,
2323
# }
24+
2425
# selectedunit = conversion[units]
2526
# result = selectedunit * int(distance)
2627

27-
# print(f"\n{distance} ft is {result} m")
28-
2928
## VERSION 4 BELOW
3029

3130
distance = input("\nWhat is the distance? ")
32-
input_units = input("\nWhat are the input units? Your choices are feet, miles, meters, or km. ")
33-
output_units = input("\nWhat are the output units? Your choices are feet, miles, meters, or km. ")
31+
input_units = input("\nWhat are the input units? Your choices are feet, miles, meters, km, yard, or inch. ")
32+
output_units = input("\nWhat are the output units? Your choices are feet, miles, meters, km, yard, or inch. ")
3433

3534
conversion = {
3635
'feet': 0.3048,
3736
'miles': 1609.34,
3837
'meters': 1,
3938
'km': 1000,
39+
'yard': 0.9144,
40+
'inch': 0.0254,
4041
}
4142

4243
inputresults = conversion[input_units]

code/kaceyb/python/lab05/lab_05.py

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# RANDOM TEST of '\n' concatinated to the file.write #
2+
3+
# def get_greeting(name):
4+
# return f'Good evening {name}'
5+
# message = get_greeting('Eric')
6+
# file = open('get_greeting.txt', 'a')
7+
8+
# file.write(message + '\n')
9+
# file.close()
10+
11+
# try:
12+
# num = int(input('Enter a number: '))
13+
# divide_num = 100/num
14+
# except (ValueError, ZeroDivisionError):
15+
# print('Please enter a number other than zero')
16+
# # print(ex, 'printing the ex error')
17+
# # print(type(ex))
18+
# # except ZeroDivisionError:
19+
# # print('Numbers cannot = 0')
20+
# else:
21+
# print('We are printing the else clause')
22+
23+
# message = input('Enter a number: ')
24+
25+
# try:
26+
# numbers = float(message)
27+
# except ValueError:
28+
# print('Please enter a number')
29+
# else:
30+
# print('Your number converted successfully')
31+
# finally:
32+
# print('Finally is printing')
33+
34+
# names = ['Peter', 'Parker']
35+
36+
# while True:
37+
# message = input('Enter a number:')
38+
# try:
39+
# number = int(message)
40+
# names[number] #names[4] creates an out of index range error
41+
# break
42+
# except(ValueError, IndexError) as error:
43+
# if type(error) == IndexError:
44+
# print('We have an index error')
45+
# else:
46+
# print('Pleaes enter a valid number')
47+
# # print(error, 'Printing except error')
48+
49+
# print('No error has occured')
50+
51+
52+
# Lab 5: Pick6
53+
54+
# Have the computer play pick6 many times and determine net balance.
55+
56+
# 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.
57+
58+
# A ticket contains 6 numbers, 1 to 99, and the number of matches between the ticket and the winning numbers determines the payoff.
59+
# Order matters, if the winning numbers are [5, 10] and your ticket numbers are [10, 5] you have 0 matches.
60+
# 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).
61+
62+
# a ticket costs $2
63+
# if 1 number matches, you win $4
64+
# if 2 numbers match, you win $7
65+
# if 3 numbers match, you win $100
66+
# if 4 numbers match, you win $50,000
67+
# if 5 numbers match, you win $1,000,000
68+
# if 6 numbers match, you win $25,000,000
69+
70+
# 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.
71+
# Another function could be num_matches(winning, ticket) which returns the number of matches between the winning numbers and the ticket.
72+
# Steps
73+
74+
# Generate a list of 6 random numbers representing the winning tickets
75+
# Start your balance at 0
76+
# Loop 100,000 times, for each loop:
77+
# Generate a list of 6 random numbers representing the ticket
78+
# Subtract 2 from your balance (you bought a ticket)
79+
# Find how many numbers match
80+
# Add to your balance the winnings from your matches
81+
# After the loop, print the final balance
82+
83+
84+
# VERSION 1 #
85+
import random
86+
87+
88+
def num_matches(winning, ticket):
89+
matches = 0
90+
for number in range(6):
91+
# print(winning[number], ticket[number])
92+
93+
if winning[number] == ticket[number]:
94+
# print("YOU WIN!")
95+
matches += 1
96+
return matches
97+
98+
99+
# Generate a list of 6 random numbers representing the winning tickets
100+
101+
102+
def pick6():
103+
ticket_numbers = []
104+
for x in range(6):
105+
# print(x)
106+
ticket_numbers.append(random.randint(1, 99))
107+
# print(ticket_numbers)
108+
return ticket_numbers
109+
110+
111+
winning_ticket = pick6()
112+
earnings = 0
113+
runs = 100000
114+
expenses = runs * 2
115+
116+
for x in range(runs):
117+
118+
match_counter = 0
119+
120+
match_counter += num_matches(winning_ticket, pick6())
121+
122+
if match_counter == 1:
123+
earnings += 4
124+
elif match_counter == 2:
125+
earnings += 7
126+
elif match_counter == 3:
127+
earnings += 100
128+
elif match_counter == 4:
129+
earnings += 50000
130+
elif match_counter == 5:
131+
earnings += 1000000
132+
elif match_counter == 6:
133+
earnings += 25000000
134+
135+
payout = earnings - expenses
136+
137+
print(payout)
138+
139+
140+
# VERSION 2 #
141+
142+
143+
roi = (earnings - expenses) / expenses
144+
145+
146+
print(roi)

code/kelin/Unit-converter.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# kelin-lab02-unit-converter
2+
3+
# Version 1
4+
# Ask the user for the number of feet, and print out the equivalent distance in meters. Hint: 1 ft is 0.3048 m.
5+
6+
from operator import truediv
7+
8+
9+
feet_to_meters = {'ft': 0.3048}
10+
11+
number_feet = input("\nPlease enter the number of feet: ")
12+
13+
number_feet = int(number_feet)
14+
15+
meters = (feet_to_meters['ft'] * number_feet)
16+
17+
print((number_feet), "feet is", (meters), "meters")
18+
19+
# Version 2
20+
21+
# Allow the user to also enter the units. Then depending on the units, convert the distance into meters. The units we'll allow are feet, miles, meters, and kilometers.
22+
23+
# 1 ft is 0.3048 m
24+
# 1 mi is 1609.34 m
25+
# 1 m is 1 m
26+
# 1 km is 1000 m
27+
28+
meter = {
29+
"ft": 0.3048,
30+
"mi": 1609.34,
31+
"m": 1,
32+
"km": 1000,
33+
"yd": 0.9144,
34+
"in": 0.0254
35+
}
36+
37+
while True:
38+
number = input("Enter the distance: ")
39+
unit = input("Enter the unit - ft - mi - m - km - yd - in: ")
40+
if unit == 'ft':
41+
print((number), "feet is", (int(number) * (meter["ft"])), "meters")
42+
elif unit == 'mi':
43+
print((number), "miles is", (int(number) * (meter["mi"])), "meters")
44+
elif unit == 'm':
45+
print((number), "meters is", (int(number) * (meter["m"])), "meters")
46+
elif unit == 'km':
47+
print((number), "kilometers is", (int(number) * (meter["km"])), "meters")
48+
elif unit == 'yd':
49+
print((number), "yards", (int(number) * (meter["yd"])), "meters")
50+
elif unit == 'in':
51+
print((number), "inches is", (int(number) * (meter["in"])), "meters")
52+
else:
53+
print("Invalid unit")
54+
55+
# Verson 3
56+
57+
# Added support for yards, and inches.
58+
59+
# 1 yard is 0.9144 m
60+
# 1 inch is 0.0254 m
61+
62+
# Version 4
63+

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...............................................................")

0 commit comments

Comments
 (0)