Menu
Coddy logo textTech

מגבלות

שיעור 6 מתוך 7 בקורס מחולל עובדות אקראיות – פרויקט Python של Coddy.

בואו נוסיף כמה מגבלות

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 אונליין