Skip to content

Commit ab844a1

Browse files
authored
Merge pull request #112 from PdxCodeGuild/kacey-lab08-dadjoke-api
Kacey lab08 dadjoke api
2 parents d20ccd1 + 8f0defa commit ab844a1

File tree

15 files changed

+529
-0
lines changed

15 files changed

+529
-0
lines changed
File renamed without changes.

code/kaceyb/python/lab06/lab_06.py

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Let's convert a dollar amount into a number of coins. The input will be the total amount, the output will be the number of quarters, dimes, nickles, and pennies.
2+
# Always break the total into the highest coin value first, resulting in the fewest amount of coins. For this, you'll have to use floor division //,
3+
# which throws away the remainder. 10/3 is 3.333333, 10//3 is 3.
4+
5+
# Welcome to the Change Maker 5000 (tm)
6+
# Enter a dollar amount: 1.36
7+
# 5 quarters, 1 dime, and 1 penny
8+
# Would you like make more change? yes
9+
# Enter a dollar amount: 0.67
10+
# 2 quarters, 1 dime, 1 nickel, 2 pennies
11+
# Would you like make more change? no
12+
# Have a good day!
13+
14+
# Version 2 (optional)
15+
16+
# Instead of hard-coding the coins, store them in a list of tuples. This way you can make custom coins.
17+
18+
# coins = [
19+
# ('half-dollar', 50),
20+
# ('quarter', 25),
21+
# ('dime', 10),
22+
# ('nickel', 5),
23+
# ('penny', 1)
24+
# ]
25+
26+
27+
coins = [
28+
("half-dollar", 50),
29+
("quarter", 25),
30+
("dime", 10),
31+
("nickel", 5),
32+
("penny", 1),
33+
]
34+
35+
while True:
36+
37+
dollar_amount = "" # dollar_amount needs to be defined before used further on, dollar_amount equals empty string
38+
print("Welcome to the Change Maker 5000")
39+
while (
40+
type(dollar_amount) != float
41+
): # while the type of dollar_amount does NOT equal a float
42+
dollar_amount = input(
43+
"Enter a dollar amount: $"
44+
) # dollar_amount equals user-input of dollar_amount as a "string" all inputs are strings
45+
try:
46+
dollar_amount = float(
47+
dollar_amount
48+
) # try to convert dollar_amount to a float
49+
# print(type(dollar_amount))
50+
except:
51+
print(
52+
f"Please enter a valid float: example is '1.57'"
53+
) # goes into this line when the user enters an invalid input
54+
dollar_amount = dollar_amount * 100
55+
half_dollars = dollar_amount // 50
56+
# dollar_amount = dollar_amount-(half_dollars * 50)
57+
dollar_amount = dollar_amount % 50
58+
# print(dollar_amount)
59+
# print(half_dollars)
60+
61+
quarters = dollar_amount // 25
62+
dollar_amount = dollar_amount - (quarters * 25)
63+
# print(quarters)
64+
#
65+
dimes = dollar_amount // 10
66+
dollar_amount = dollar_amount - (dimes * 10)
67+
# print(dimes)
68+
69+
nickels = dollar_amount // 5
70+
dollar_amount = dollar_amount - (nickels * 5)
71+
# print(nickels)
72+
73+
# print('total before', dollar_amount)
74+
75+
pennies = dollar_amount / float(1)
76+
# print('number of pennies', pennies)
77+
penny_amount = pennies * float(1)
78+
dollar_amount = dollar_amount - penny_amount
79+
# print(dollar_amount)
80+
# print(pennies)
81+
82+
# print(f"{int(half_dollars)}:Half Dollars {int(quarters)}:Quarters {int(dimes)}:Dimes {int(nickels)}:Nickles {int(pennies)}:Pennies")
83+
statement = ""
84+
if half_dollars > 0:
85+
statement = statement + " " + str(int(half_dollars)) + " " + "Half Dollars"
86+
87+
if quarters > 0:
88+
statement = statement + " " + str(int(quarters)) + " " + "Quarters"
89+
90+
if dimes > 0:
91+
statement = statement + " " + str(int(dimes)) + " " + "Dimes"
92+
93+
if nickels > 0:
94+
statement = statement + " " + str(int(nickels)) + " " + "Nickels"
95+
96+
if pennies > 0:
97+
statement = statement + " " + str(int(pennies)) + " " + "Pennies"
98+
99+
print(statement)
100+
101+
done = input("Would you like to make more change? yes or no: ").lower()
102+
103+
if done == "no":
104+
print("Goodbye")
105+
quit()

code/kaceyb/python/lab08/lab_08.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# PART 1 #
2+
3+
4+
from logging import exception
5+
import requests
6+
7+
8+
# response = requests.get("https://icanhazdadjoke.com", headers={
9+
# 'Accept': 'application/json'})
10+
11+
# # print(response)
12+
# # print(type(response))
13+
# # print(response.text)
14+
# # print(response.status_code)
15+
16+
17+
# # joke = response.text
18+
# joke = response.json()
19+
# # print(joke)
20+
21+
# answer = input('Wanna hear a joke, Yes or No?: ').lower()
22+
23+
# if answer == 'yes':
24+
# print(joke['joke'])
25+
# else:
26+
# print('Fine, Gbyeeee')
27+
28+
# PART 2 #
29+
30+
search_term = input("Enter a search term: ")
31+
32+
33+
response = requests.get(
34+
f"https://icanhazdadjoke.com/search?term={search_term}",
35+
headers={"Accept": "application/json"},
36+
)
37+
38+
# print(response)
39+
40+
# joke = response.text
41+
42+
joke = response.json()
43+
jokes = joke["results"]
44+
try:
45+
46+
for joke in jokes:
47+
print(joke["joke"])
48+
another_joke = input("Want another joke? yes/no: ").lower()
49+
if another_joke == "no":
50+
break
51+
52+
except exception as e:
53+
print(f"error {e}")
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
class Beer:
2+
def __init__(self, name, size):
3+
self.name = name
4+
self.size = size
5+
6+
def drinkable(self):
7+
8+
if self.name == "keystone":
9+
print("Don't drink")
10+
11+
if self.name == "guiness":
12+
print("Sure have a sip")
13+
14+
else:
15+
print('DRINK UP')
16+
17+
18+
19+
b = Beer('budlight', '12oz')
20+
newbeer = Beer("guiness", '12oz')
21+
newbeer.drinkable()
22+
b.drinkable()
23+
24+
25+
26+
27+
28+
29+
# print(b.name)
30+
# print(b.size)
31+
32+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
red, green, yellow, blue, indigo, chartuce
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
green
2+
yellow
3+
indigo
4+
chartuce
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Adding content to file
2+
MORE TEXT
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Legacy Method
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# FIRST PIECE #
2+
3+
# class User:
4+
# def __init__(self, username, email):
5+
# self.username = username
6+
# self.email = email
7+
8+
# bruce = User('criticbruce', '[email protected]')
9+
10+
# print(bruce.username)
11+
12+
# SECOND PIECE #
13+
14+
import math
15+
def distance(p1, p2):
16+
dx = p1['x'] - p2['x']
17+
dy = p1['y'] - p2['y']
18+
return math.sqrt(dx*dx + dy*dy)
19+
20+
p1 = {'x': 5, 'y':2}
21+
p2 = {'x': 8, 'y':4}
22+
print(distance(p1, p2))
23+
24+
class Point:
25+
def __init__(self, x, y):
26+
self.x = x
27+
self.y = y
28+
29+
def distance(self, p):
30+
dx = self.x - p.x
31+
dy = self.y - p.y
32+
return math.sqrt(dx*dx + dy*dy)
33+
34+
p1 = Point(5, 2) # call the initializer, instantiate the class
35+
36+
p1 = (5,2)
37+
p2 = Point(8,4)
38+
39+
# print(p1.x)
40+
# print(p1.y)
41+
print(type(p1))
42+
# print(p1.distance(p2))
43+
44+
name = [1,2,3]
45+
print(type(name))
46+
print(name.sort())
47+
48+
number = input("What's your favorite number?: ")
49+
print(type(number))
50+
51+
52+
53+
54+
55+
56+
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# with open('example.txt', 'a') as file:
2+
# text = file.write('\nMORE TEXT')
3+
# print(text)
4+
5+
# file = open('example2.txt', 'w')
6+
# text = file.write('Legacy Method')
7+
# print(text)
8+
# file.close()
9+
10+
# with open('colors.txt') as file:
11+
# colors = file.read()
12+
13+
# colors = file.read().split()
14+
# print(colors)
15+
16+
# with open('colors.txt', 'w') as file:
17+
# text = file.write()
18+
# print(text)
19+
20+
# import datetime
21+
22+
#read file
23+
24+
# start = datetime.datetime.now()
25+
# with open('phonebook.txt') as file:
26+
# phone_book = file.read()
27+
# end = datetime.datetime.now()
28+
29+
# print(f'Your file loaded in {end-start}')
30+
31+
# with open('phonebook.txt', 'w') as file:
32+
# text = file.write('')
33+
# print(text)
34+
35+
# with open('phonebook.txt') as file:
36+
# phone_book = file.read()
37+
38+
# phone_book = phone_book.split('\n')
39+
# name = input('Lookup name: ')
40+
41+
# found_entry = False
42+
# for entry in phone_book:
43+
# if name.lower() in entry.lower():
44+
# print(entry)
45+
# found_entry = True
46+
47+
# if not found_entry:
48+
# print('Contact not found')
49+
# name = input('Enter new contact name: ')
50+
# phone_number = input(f'Enter the number for : {name}')
51+
52+
# phone_book.append(name + " " + phone_number)
53+
54+
# phone_book.sort()
55+
# with open('phonebook2.txt', 'w') as file2:
56+
# file2.write('\n'.join(phone_book))
57+
58+
59+
# print(type(phone_book))
60+
# print(phone_book)
61+
# def Convert(lst):
62+
# res_dct = {lst[i]: lst[i + 1] for i in range (0, len(lst), 2)}
63+
# return res_dct
64+
65+
# with open('phonebook.txt', 'r') as file:
66+
# color = file.read()
67+
# color = color.split('\n')
68+
# color = Convert(color)
69+
# print(color)

0 commit comments

Comments
 (0)