Skip to content

Commit 2ab931f

Browse files
committed
adding lab 14 version 1 and 2
1 parent f7732fc commit 2ab931f

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

Code/matthew/python/Labs/lab14.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""
2+
Dad joke API
3+
"""
4+
import requests
5+
import time
6+
'''
7+
response = requests.get("https://icanhazdadjoke.com", headers={
8+
'Accept': 'application/json'
9+
})
10+
11+
dad_jokes = response.json()
12+
13+
joke = dad_jokes['joke']
14+
15+
# print(joke)
16+
'''
17+
18+
# --- Version 2
19+
20+
response = requests.get('https://icanhazdadjoke.com/search', headers={
21+
'Accept': 'application/json'
22+
})
23+
24+
dad_jokes_list = response.json()
25+
26+
# print(dad_jokes_list['results'][1]['joke'])
27+
counter = 0
28+
joke = dad_jokes_list['results'][counter]['joke']
29+
break_loop = ['no', 'stop', 'quit', 'q', 'exit']
30+
while True:
31+
print('Joke incoming')
32+
time.sleep(.5)
33+
print('In three')
34+
time.sleep(.75)
35+
print('two')
36+
time.sleep(1)
37+
print('one')
38+
time.sleep(1.25)
39+
print(f"\njoke")
40+
counter += 1
41+
again = input('\nWould you like to hear another one?\n')
42+
if again.lower() in break_loop :
43+
break

0 commit comments

Comments
 (0)