Riddle
```python
import random
def get_random_riddle():
riddles = [
{"question": "What has keys but can't open locks?", "answer": "Piano"},
{"question": "What comes once in a minute, twice in a moment, but never in a thousand years?", "answer": "The letter 'M'"},
{"question": "I speak without a mouth and hear without ears. I have no body, but I come alive with the wind. What am I?", "answer": "An echo"},
# Add more riddles as needed
]
return random.choice(riddles)
def play_riddle_game():
score = 0
num_riddles = 3 # You can adjust the number of riddles
print("Welcome to the Riddle Game!")
for _ in range(num_riddles):
riddle = get_random_riddle()
print("\nRiddle:")
print(riddle["question"])
user_answer = input("Your answer: ").strip().capitalize()
if user_answer == riddle["answer"]:
print("Correct! Well done.")
score += 1
else:
print(f"Sorry, the correct answer is '{riddle['answer']}'.")
print(f"\nGame Over! Your final score is {score}/{num_riddles}.")
if __name__ == "__main__":
play_riddle_game()
```
Comments
Post a Comment