Skip to content

Commit 5fb512d

Browse files
committed
finished lab08 dad jokes
1 parent 891d632 commit 5fb512d

File tree

4 files changed

+149
-14
lines changed

4 files changed

+149
-14
lines changed

code/kaceyb/python/lab08/lab_08.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# PART 1 #
2+
3+
4+
import requests
5+
6+
7+
# response = requests.get("https://icanhazdadjoke.com", headers={
8+
# 'Accept': 'application/json'})
9+
10+
# # print(response)
11+
# # print(type(response))
12+
# # print(response.text)
13+
# # print(response.status_code)
14+
15+
16+
# # joke = response.text
17+
# joke = response.json()
18+
# # print(joke)
19+
20+
# answer = input('Wanna hear a joke, Yes or No?: ').lower()
21+
22+
# if answer == 'yes':
23+
# print(joke['joke'])
24+
# else:
25+
# print('Fine, Gbyeeee')
26+
27+
# PART 2 #
28+
29+
search_term = input("Enter a search term: ")
30+
31+
32+
response = requests.get(
33+
f"https://icanhazdadjoke.com/search?page=1", headers={"Accept": "application/json"}
34+
)
35+
36+
# print(response)
37+
38+
# joke = response.text
39+
40+
joke = response.json()
41+
jokes = joke["results"]
42+
43+
for joke in jokes:
44+
print(joke["joke"])
45+
another_joke = input("Want another joke? yes/no: ").lower()
46+
if another_joke == "no":
47+
break
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: 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+

code/kaceyb/python/notes/lesson07.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
# write.writerow(['Lake Oswego', 'OR', '97032'])
88

99

10-
with open('location.csv') as file:
11-
reader = csv.reader(file)
10+
# with open('location.csv') as file:
11+
# reader = csv.reader(file)
1212

1313

1414

@@ -53,20 +53,20 @@
5353

5454
from datetime import datetime, timedelta
5555

56-
# from django.forms import DateTimeInput
57-
# dt = datetime.strptime('2022/01/01', '%Y/%m/%d')
58-
# print(f'{dt.year}/{dt.month}')
56+
from django.forms import DateTimeInput
57+
dt = datetime.strptime('2022/01/01', '%Y/%m/%d')
58+
print(f'{dt.year}/{dt.month}')
5959

60-
# dt = datetime.now()
61-
# print(dt.strftime('%Y/%m'))
60+
dt = datetime.now()
61+
print(dt.strftime('%Y/%m'))
6262

63-
# dt_start = datetime(2022, 1, 1)
64-
# dt_end = datetime.now()
65-
# duration = dt_end - dt_start
66-
# print(duration)
67-
# print('days', duration.days)
68-
# print('seconds', duration.seconds)
69-
# print('total_seconds', duration.total_seconds())
63+
dt_start = datetime(2022, 1, 1)
64+
dt_end = datetime.now()
65+
duration = dt_end - dt_start
66+
print(duration)
67+
print('days', duration.days)
68+
print('seconds', duration.seconds)
69+
print('total_seconds', duration.total_seconds())
7070

7171

7272

0 commit comments

Comments
 (0)