Final words
Lesson 7 of 7 in Coddy's Random Fact Generator - Python Project course.
That's it! You have a working fact generator!
What's next? here are some ideas:
- Handling errors with inputs
- Welcome message and some input messages
- Filter facts by some condition
- Get the fact of the day (https://uselessfacts.jsph.pl/api/v2/facts/today) based on some input
- And many more…
Challenge
EasyRun the code to complete the project, and generate 3 facts :)
Try it yourself
import requests
import json
def get_fact():
response = requests.get('https://uselessfacts.jsph.pl/api/v2/facts/random')
content = response.text
data = json.loads(content)
return data['text']
n = int(input())
if n > 7:
print('Maximum number of facts per execution is 7')
elif n <= 0:
print('Minimum number of facts per execution is 1')
else:
for i in range(n):
print(get_fact())