File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ import requests
2
+
3
+ def get_joke (search_parameter ):
4
+ response = requests .get (f"https://icanhazdadjoke.com/search?term={ search_parameter } " , headers = {
5
+ 'Accept' : 'application/json'
6
+ })
7
+ data = response .json ()["results" ]
8
+ jokes = []
9
+ for item in data :
10
+ jokes .append (item ['joke' ])
11
+ return jokes
12
+
13
+ def main ():
14
+
15
+ user_input = input ("Enter a search term to return dad jokes or type 'done' to exit: " )
16
+ jokes = get_joke (user_input )
17
+ index = 0
18
+ answer = 'yes'
19
+
20
+ print (len (jokes ))
21
+
22
+ if user_input == 'done' :
23
+ exit
24
+ else :
25
+ while index < len (jokes ) and answer == 'yes' :
26
+ print (jokes [index ])
27
+ index += 1
28
+
29
+ if index == len (jokes ):
30
+ print ("We are out of jokes." )
31
+ break
32
+
33
+ answer = input (f"Would you like to see another dad joke about '{ user_input } '? Enter yes/no: " )
34
+
35
+ print ("You're welcome. Byeeeee" )
36
+
37
+ main ()
You can’t perform that action at this time.
0 commit comments