forked from csfeeser/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcat_fact_solution
More file actions
47 lines (39 loc) · 1.33 KB
/
cat_fact_solution
File metadata and controls
47 lines (39 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python3
"""Alta3 Research | Author: csfeeser@alta3.com"""
# imports always go at the top of your code
import requests
import random
r = requests.get('https://cat-fact.herokuapp.com/facts')
def name_calling():
name_list = []
for name in r.json()["all"]:
if name.get("user"):
name_list.append(f'{name["user"]["name"]["first"]} {name["user"]["name"]["last"]} is a dumb name.')
for x in name_list:
print(x)
def highest_upvotes():
upvote_list= []
for x in r.json()["all"]:
upvote_list.append(x.get("upvotes"))
print("\nThe highest upvote count was:")
print("=============================")
print(max(upvote_list))
def random_cat_fact():
fact_list= []
for x in r.json()["all"]:
fact_list.append(x.get("text"))
print("\nEnjoy a random cat fact!")
print("========================")
print(random.choice(fact_list))
def UNNECESSARILY_COMPLICATED_random_cat_fact():
fact_list= []
for x in r.json()["all"]:
fact_list.append(x.get("text"))
list_count= len(fact_list) - 1
random_fact= random.randint(0, list_count)
print("\nEnjoy a random cat fact!")
print("========================")
print(fact_list[random_fact])
name_calling()
random_cat_fact()
highest_upvotes()