forked from Shahrayar123/Python-Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathriddle.py
28 lines (21 loc) · 989 Bytes
/
riddle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import random
# Riddle game
riddles = {
"I have cities but no houses, forests but no trees, and water but no fish. What am I?": "A map",
"I am always hungry, I must always be fed. The finger I touch, will soon turn red. What am I?": "Fire",
"I am not alive, but I grow. I don't have lungs, but I need air. I don't have a mouth, but water kills me. What am I?": "Fire",
"What has a heart that doesn't beat?": "Artichoke",
"What is so fragile that saying its name breaks it?": "Silence"
}
riddle_keys = list(riddles.keys()) # Convert the dictionary keys into a list.
random.shuffle(riddle_keys) # Shuffle the list of riddle keys.
score = 0
for riddle_key in riddle_keys:
print(riddle_key)
user_answer = input("Answer: ").lower()
if user_answer == riddles[riddle_key].lower():
print("Correct!")
score += 1
else:
print("Wrong answer. Correct answer: " + riddles[riddle_key])
print("Game over! Your score is: " + str(score))