Skip to content

Commit ecbb9a3

Browse files
Merge branch 'main' into zach-lab10-atm
2 parents 8fa5260 + cc6fc0e commit ecbb9a3

File tree

5 files changed

+414
-0
lines changed

5 files changed

+414
-0
lines changed

1 Python/labs/Connect Four Mob.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
Connect Four
2+
3+
[Connect Four](https://en.wikipedia.org/wiki/Connect_Four) is a board game.
4+
Players take turns placing tokens of their color into a vertical grid.
5+
They drop to the bottom, and if anyone has four of their color in a straight line, they've won!
6+
7+
Define a module that simulates a Connect Four game.
8+
9+
This will consist of the following classes:
10+
11+
`Player`:
12+
- Properties
13+
- `name`
14+
- `color`
15+
16+
`Game`:
17+
- Properties
18+
- `board`: 7x6 board representation
19+
20+
- Methods
21+
- `get_height(position)`: returns int of how many pieces occupy a column
22+
- `move(player, position)`: adds a player token to a column after figuring out the current height of the column
23+
- `calc_winner()`: returns true if a match (four in a row) is found
24+
- `is_full()`: returns true if all board positions are occupied
25+
- `is_game_over()`: returns true if the game is over (a winner is found or the board is full)
26+
27+
28+
Create a program that simulates the _just playing moves_ of an existing Connect Four game.
29+
Do not concern yourself with figuring out who has won.
30+
31+
It will read a file that contains a history of the moves in a game.
32+
Assume the playing board is made of columns numbered 1 through 7.
33+
The file will have one line for each move (players alternate).
34+
The number in that line is the column the current player placed a token in.
35+
36+
Use the following [example move file](./connect_four/connect-four-moves.txt).
37+
Save it in something like `connect-four-moves.txt`
38+
This moves file recreates [this game](https://en.wikipedia.org/wiki/File:Connect_Four.gif).
39+
40+
* Think about how to figure out how far that token will fall in a given column.
41+
42+
* Think about how to place a token in a column.
43+
44+
* Think about how to concisely store the tokens that have been dropped in the board.
45+
46+
* Read in moves from the file.
47+
48+
* After each move, print out a representation of the board.
49+
You can use `R` and `Y` to represent the pieces.
50+
51+
## Version 2
52+
53+
* Once all moves are done, also print out what player, if any, won.
54+
55+
## Version 3
56+
57+
* Make game playable

code/justin/lab10_version1.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
'''
2+
Justin Young
3+
Lab 10
4+
Version1&2
5+
'''
6+
import time
7+
from time import time, ctime
8+
from time import mktime
9+
t = time()
10+
11+
class ATM:
12+
transactions = ''
13+
def __init__(self, money):
14+
self.money = money
15+
def check_balance(self):
16+
self.transactions += f'User checked balance of {self.money} @{ctime(t)}\n'
17+
return self.money
18+
def deposit(self, amount):
19+
self.money += amount
20+
self.transactions += f'User deposited {amount} @{ctime(t)}\n'
21+
return self.money
22+
def check_withdrawal(self, amount):
23+
if self.money < amount:
24+
self.transactions += f'User had insufficient funds to withdraw {amount} @{ctime(t)}\n'
25+
return False
26+
else:
27+
return True
28+
def withdraw(self, amount):
29+
self.money -= amount
30+
self.transactions += f'User withdrew {amount} @{ctime(t)}\n'
31+
return self.money
32+
def calc_interest(self):
33+
birth = (1983, 11, 23, 15, 58, 32, 2, 327, 0)
34+
b = mktime(birth)
35+
a = t - b
36+
years = (a / 86400) / 365
37+
c = self.money * 0.001 * years
38+
c = round(c, 2)
39+
self.transactions += f'Interest {c} calculated @{ctime(t)}\n'
40+
return c
41+
42+
def print_transactions(self):
43+
return self.transactions
44+
45+
46+
47+
48+
49+
50+
51+
52+
53+
atm = ATM(150.00) # create an instance of our class
54+
print('Welcome to the ATM')
55+
while True:
56+
command = input('Enter a command: ')
57+
if command == 'balance':
58+
balance = atm.check_balance() # call the check_balance() method
59+
print(f'Your balance is ${balance}')
60+
elif command == 'deposit':
61+
amount = float(input('How much would you like to deposit? '))
62+
atm.deposit(amount) # call the deposit(amount) method
63+
print(f'Deposited ${amount}')
64+
elif command == 'withdraw':
65+
amount = float(input('How much would you like '))
66+
if atm.check_withdrawal(amount): # call the check_withdrawal(amount) method
67+
atm.withdraw(amount) # call the withdraw(amount) method
68+
print(f'Withdrew ${amount}')
69+
else:
70+
print('Insufficient funds')
71+
elif command == 'transactions':
72+
print(atm.print_transactions())
73+
elif command == 'interest':
74+
amount = atm.calc_interest() # call the calc_interest() method
75+
atm.deposit(amount)
76+
print(f'Accumulated ${amount} in interest')
77+
elif command == 'help':
78+
print('Available commands:')
79+
print('balance - get the current balance')
80+
print('deposit - deposit money')
81+
print('withdraw - withdraw money')
82+
print('transactions - check prior user transactions')
83+
print('interest - accumulate interest')
84+
print('exit - exit the program')
85+
elif command == 'exit':
86+
break
87+
else:
88+
print('Command not recognized')

code/matt/python/lab09-quotes.py

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#Matt Nichols
2+
#Lab09
3+
4+
#Version 1
5+
6+
import requests
7+
import pprint
8+
9+
r = requests.get("https://favqs.com/api/qotd")
10+
11+
#Getting the authors name
12+
author = r.json()['quote']['author']
13+
print(f'Author: {author}')
14+
15+
#Getting the quote itself
16+
quote = r.json()['quote']['body']
17+
print(f'Quote: {quote}')
18+
19+
#For aesthectics
20+
lines_for_looks = ("----------------------------------")
21+
print(lines_for_looks)
22+
23+
#Version 1 completed
24+
#Version 2 below
25+
26+
#For aesthectics
27+
lines_for_looks = ("----------------------------------")
28+
29+
#Function for allowing the user to go to the next page IF desired
30+
def do_keep_going():
31+
while True:
32+
user_input = input("Would you like to continue to the next page of quotes?\nEnter 'yes' to continue OR 'no' to exit: ")
33+
if user_input == "no":
34+
return user_input
35+
if user_input == "yes":
36+
return user_input
37+
print(f"{lines_for_looks}\nSorry, {user_input} was NOT readable. Ensure you type 'yes' OR 'no' ")
38+
39+
#Function for allowing the user to view how many quotes are on the next page
40+
def do_view():
41+
while True:
42+
user_input = input("Would you like to view the quotes?\nEnter 'yes' to continue OR 'no' to exit: ")
43+
if user_input == "no":
44+
return user_input
45+
if user_input == "yes":
46+
return user_input
47+
print(f"{lines_for_looks}\nSorry, {user_input} was NOT readable. Ensure you type 'yes' OR 'no' ")
48+
49+
#Greeting
50+
print("Hello and Welcome, User! ")
51+
52+
#'''Keyword''' for my params allowing the user to enter what tags they want to read
53+
keyword = input("Enter a keyword to search for quotes: ")
54+
55+
#'''page''' for them to start on page one and to continue IF wanted
56+
page = 1
57+
58+
#requesting a response from the following down below
59+
r = requests.get(f'https://favqs.com/api/quotes',
60+
params={'page': page, 'filter': keyword},
61+
headers={'Authorization': 'Token token="855df50978dc9afd6bf86579913c9f8b"'})
62+
63+
#The variable '''quotes''' is allowing us to fall into a deeper level with the url and pull what we desire from the following dictionary 'qoutes'
64+
quotes = r.json()['quotes']
65+
66+
#The variable '''last_page''' allows us to use a boolean value for our while loop and continue on to the next page if optional
67+
last_page = r.json()['last_page']
68+
69+
while True:
70+
71+
#Tells the user how many quotes are on the next page
72+
print(lines_for_looks)
73+
print(f'There are {len(quotes)} quotes that appear on Page{page} with this keyword')
74+
print(lines_for_looks)
75+
76+
view = do_view()
77+
if view == 'no':
78+
break
79+
80+
#prints the auther and quote
81+
for q in quotes:
82+
print(f"Author: {q['author']}")
83+
print(f"Quote: {q['body']}")
84+
print(lines_for_looks)
85+
86+
#Pulling the '''last_page''' variable in
87+
#IF it's the last page it will break
88+
if last_page == True:
89+
print("That's all the quotes from this keyword")
90+
break
91+
#If it's NOT the last page it will give them the option to continue OR exit
92+
if last_page == False:
93+
keep_going = do_keep_going()
94+
if keep_going == 'no':
95+
break
96+
elif keep_going == 'yes':
97+
#Pulling in one of the values of are query
98+
page = page + 1
99+
#We have to print this out again or it will continue to print out the same results
100+
#This is due to the variable '''r''' being a contant and out of the while loop
101+
r = requests.get(f'https://favqs.com/api/quotes',
102+
params={'page': page, 'filter': keyword},
103+
headers={'Authorization': 'Token token="855df50978dc9afd6bf86579913c9f8b"'})
104+
quotes
105+
106+
print("Thanks for your time")
107+
108+
#Version 2 completed
109+
110+
111+
112+
113+
114+
115+
116+
117+
118+
119+
120+
121+
# print(r)
122+
# pprint.pprint(r.text)
123+
# print("------")
124+
# pprint.pprint(r.json())

code/muki/lab04b.py

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

0 commit comments

Comments
 (0)