Menu
CoddyTech

局限性

Coddy 随机事实生成器:Python 项目 课程的第 6 课,共 7 课。

我们来添加一些限制

challenge icon

挑战

简单

如果输入的数字大于 7,输出 "Maximum number of facts per execution is 7"。

如果输入的数字小于 0,输出 "Minimum number of facts per execution is 1"。

在这个项目中,我们假设输入始终是一个数字。

亲手试试

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())
for i in range(n):
    print(get_fact())

随机事实生成器:Python 项目中的所有课

自己练习: Python 在线编译器