相关文章推荐
def fetch_random_fact():
url = "http://api.explinks.com/v2/scd20240805667911152209/python-random-facts-game"
response = requests.get(url)
if response.status_code == 200:
data = response.json()
return data.get('fact', 'No fact found.')
else:
return 'Error fetching fact.'
def main():
print("Welcome to the Random Facts Quiz!")
while True:
input("Press Enter to get a new fact...")
fact = fetch_random_fact()
print(f"Did you know? {fact}")
play_again = input("Would you like another fact? (yes/no): ").strip().lower()
if play_again != 'yes':
print("Thanks for playing! Goodbye!")
break
if __name__ == "__main__":
main()

注意事项

 
推荐文章