Skip to content

Commit 8fa5260

Browse files
Merge branch 'main' into zach-lab10-atm
2 parents 357b069 + ee26d2e commit 8fa5260

File tree

6 files changed

+237
-1
lines changed

6 files changed

+237
-1
lines changed

1 Python/labs/MiniCapstone.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Mini Capstone
2+
3+
For your final Python project, build a program that solves a problem or accomplishes a task. Your program needs to utilize an external library (not part of the Python standard library -- this needs to be something that you `pip install`).
4+
5+
The functionality of the program is up to you -- use this as an opportunity to get creative. Sometimes students explore an idea they want to use for their capstone project or solve an actual problem they have. For a list of Python libraries to consider using in this project, check out https://awesome-python.com
6+
7+
### Examples of previous projects
8+
9+
- Japanese character matching game in PyGame
10+
- Kroger API and Pandas to find cheapest products
11+
- Communicating with hardware GPS
12+
- Cement bond log reader to create annotated matplotlib PDFs
13+
- PySimpleGUI 4-function calculator
14+
- BeautifulSoup to work with Kindle notes
15+
- PyDictionary/Deep Translator/Google Translate/EasyGUI Arabic word of the day
16+
- Pygal stock price charts based on Yahoo financial data
17+
- Aquarium calculator, logger, and grapher
18+
- Animal Crossing critter logger and grapher
19+
- Router traffic / adventure game in Tkinter
20+
- Stock information from Yahoo financial data w/ Plotly charts
21+
- HNT finder app
22+
- Hangman with custom graphics in Tkinter
23+
- Dinner decider app in Tkinter using Yelp API
24+
- Parse medical residency applications into spreadsheets
25+
- Command line packaged calculator
26+
- Web scraping Yelp and visualizing data using matplotlib
27+
- Tic tac toe in Tkinter
28+
- 4 function calculator in Tkinter packaged into an exe
29+
- BeautifulSoup and Pandas to make spreadsheets of basketball stats
30+
- Tkinter quotes and calculator
31+
- BeautifulSoup and Pandas to get stock information
32+
- Tic tac toe in Pygame
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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+
import random
32+
33+
face_cards = {
34+
"K": 10,
35+
"Q": 10,
36+
"J": 10,
37+
"10": 10,
38+
"9": 9,
39+
"8": 8,
40+
"7": 7,
41+
"6": 6,
42+
"5": 5,
43+
"4": 4,
44+
"3": 3,
45+
"2": 2,
46+
"A": 1
47+
}
48+
# #======================
49+
# # Input validation fix
50+
# #======================
51+
# while True:
52+
# try:
53+
# question_1 = int(input("What's your first card?: "))
54+
# question_2 = int(input("What's your second card?: "))
55+
# question_3 = int(input("What's your third card?: "))
56+
# except ValueError:
57+
# print("Invalid Value, try agian")
58+
# continue
59+
# except TypeError:
60+
# print("Please enter a number")
61+
# continue
62+
# # else:
63+
# # break
64+
65+
66+
67+
68+
card_total = 0
69+
70+
while True:
71+
if question_1 in face_cards:
72+
card_total += int(face_cards[question_1])
73+
print(f"question_1: {question_1}")
74+
75+
if question_2 in face_cards:
76+
card_total += int(face_cards[question_2])
77+
print(f"question_2: {question_2}")
78+
79+
if question_3 in face_cards:
80+
card_total += int(face_cards[question_3])
81+
print(f"question_3: {question_3}")
82+
break
83+
else:
84+
print("Not valid")
85+
break
86+
else:
87+
print("Not valid")
88+
break
89+
else:
90+
print("Not valid")
91+
break
92+
if card_total < 17:
93+
print(f"Hit {card_total}")
94+
elif 17 <= card_total < 21:
95+
print(f"Stay {card_total}")
96+
elif card_total == 21:
97+
print(f"Backjack! {card_total}")
98+
elif card_total > 21:
99+
print(f"Already Busted {card_total}")
100+
else:
101+
print("Not Valid")
102+
103+
104+
105+
106+
107+
# Version 2 (optional)
108+
109+
# Aces can be worth 11 if they won't put the total point value of both cards over 21. Remember that you can have multiple aces in a hand.
110+
# Try generating a list of all possible hand values by doubling the number of values in the output whenever you encounter an ace.
111+
# For one half, add 1, for the other, add 11. This ensures if you have multiple aces that you account for the full range of possible values.

code/jonpan/lab09_v1.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#Lab09: Quotes API
2+
3+
import requests
4+
import pprint
5+
6+
response = requests.get("https://favqs.com/api/qotd", headers={'Accept': 'application/json'})
7+
data = response.json()
8+
9+
pprint.pprint(data)
10+
# print(type(data))
11+
12+
# print(f"\nAuthor: {data['quote']['author']}")
13+
# print(f"\nQuote: {data['quote']['body']}")
14+
15+
quotes = {
16+
'Author': data['quote']['author'],
17+
'Quote': data['quote']['body']
18+
}
19+
20+
print(f"\nAuthor: {quotes['Author']}")
21+
print(f"\nQuote: {quotes['Quote']}")

code/jonpan/lab09_v2.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import requests
2+
import pprint
3+
4+
def print_results(p_num, search_term):
5+
response = requests.get(f"https://favqs.com/api/quotes?page=<page>&filter={search_term}", params={'page':{p_num}},
6+
headers={'Accept': 'application/json', 'Authorization': 'Token token="855df50978dc9afd6bf86579913c9f8b"'})
7+
data = response.json()
8+
9+
for i in range(len(data['quotes'])):
10+
print(f"\nAuthor: {data['quotes'][i]['author']}")
11+
print(f"\nQuote: {data['quotes'][i]['body']}")
12+
13+
search_term = input("enter a keyword to search for quotes: ")
14+
p_num = 1
15+
16+
# search_term and p_num are defined outside the function so need to be included in the function(here)
17+
18+
while True:
19+
print_results(p_num, search_term)
20+
cont = input("enter 'next page' or 'done' ")
21+
if cont == 'done':
22+
print("Goodbye")
23+
break
24+
else:
25+
p_num += 1
26+
27+
28+
# pprint.pprint(data)
29+
# print(f"\nAuthor: {data['quotes'][0]['author']}")

code/zach/lab09-quotes-api.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import requests
2+
3+
def version1():
4+
response = requests.get('https://favqs.com/api/qotd', headers={'Accept': 'application/json'})
5+
6+
quote = response.json()['quote']['body']
7+
author = response.json()['quote']['author']
8+
9+
return print(f'"{quote}" - {author}')
10+
11+
def version2():
12+
page = 1
13+
index = 0
14+
search_term = input('Enter a keyword to search for quotes: ')
15+
16+
while True:
17+
response = requests.get(f'https://favqs.com/api/quotes?page={page}&filter={search_term}', headers={
18+
'Accept': 'application/json',
19+
'Authorization': 'Token token="855df50978dc9afd6bf86579913c9f8b"'})
20+
last_page = response.json()['last_page']
21+
quotes = response.json()['quotes']
22+
num_quotes = len(quotes)
23+
24+
if last_page == False:
25+
print(f'{num_quotes} quotes associated with {search_term} - page {page}')
26+
27+
for quote in quotes:
28+
print(f"'{response.json()['quotes'][index]['body']}' - {response.json()['quotes'][index]['author']}")
29+
index += 1
30+
31+
answer = input("Enter 'next page' or 'done': ")
32+
33+
if answer == 'done':
34+
return
35+
elif answer == 'next page':
36+
page += 1
37+
index = 0
38+
39+
40+
def main():
41+
#version1()
42+
version2()
43+
44+
main()

get_greeting.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)