Skip to content

Instantly share code, notes, and snippets.

@dmd
Created March 17, 2023 01:03
Show Gist options
  • Save dmd/e0d736d8122835e7159a497e20917f9e to your computer and use it in GitHub Desktop.
Save dmd/e0d736d8122835e7159a497e20917f9e to your computer and use it in GitHub Desktop.
import requests
from fuzzywuzzy import fuzz
from fuzzywuzzy import process
# Function to get a random question from the Jeopardy API
def get_random_question():
response = requests.get("http://jservice.io/api/random")
question_data = response.json()[0]
return question_data
# Function to check the answer using fuzzy matching
def is_correct_answer(user_answer, correct_answer):
similarity = fuzz.ratio(user_answer.lower(), correct_answer.lower())
return similarity > 80
# Main script
def main():
question_data = get_random_question()
question = question_data["question"]
category = question_data["category"]["title"]
correct_answer = question_data["answer"]
print(f"Category: {category}")
print(f"Question: {question}")
user_answer = input("Your answer: ")
if is_correct_answer(user_answer, correct_answer):
print("Correct!")
else:
print(f"Sorry, the correct answer is: {correct_answer}")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment