Skip to content

Commit 687c883

Browse files
authored
Merge pull request Shahrayar123#67 from SinanTokmak/Riddle
Addding New The Riddle Game
2 parents 087602d + 3bf23ab commit 687c883

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

Riddle/readme.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Random Riddle Game
2+
3+
This is a Python program that presents a series of riddles to the user in a random order. The program uses a dictionary to store the riddles and their corresponding answers, and the `random` module to present the questions in a random order.
4+
5+
## Getting Started
6+
7+
To run the program, you'll need to have Python installed on your computer. You can download Python from the official website: https://www.python.org/downloads/
8+
9+
Once you have Python installed, you can run the program by opening a terminal or command prompt, navigating to the directory where you saved the `random_riddle_game.py` file, and typing:
10+
11+
12+
## Usage
13+
14+
When you run the program, it will present a series of riddles to the user. The user must enter their answer for each riddle, and the program will tell them whether their answer was correct or not. At the end of the game, the user's score will be displayed.
15+
16+
You can customize the program by adding more riddles to the `riddles` dictionary in the code. Each riddle should be a key in the dictionary, with the corresponding answer as the value.
17+
18+
## Contributing
19+
20+
If you'd like to contribute to this project, feel free to fork the repository and submit a pull request. You can also open an issue if you find a bug or have a suggestion for improvement.

Riddle/riddle.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import random
2+
3+
# Riddle game
4+
5+
riddles = {
6+
"I have cities but no houses, forests but no trees, and water but no fish. What am I?": "A map",
7+
"I am always hungry, I must always be fed. The finger I touch, will soon turn red. What am I?": "Fire",
8+
"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",
9+
"What has a heart that doesn't beat?": "Artichoke",
10+
"What is so fragile that saying its name breaks it?": "Silence"
11+
}
12+
13+
riddle_keys = list(riddles.keys()) # Convert the dictionary keys into a list.
14+
15+
random.shuffle(riddle_keys) # Shuffle the list of riddle keys.
16+
17+
score = 0
18+
19+
for riddle_key in riddle_keys:
20+
print(riddle_key)
21+
user_answer = input("Answer: ").lower()
22+
if user_answer == riddles[riddle_key].lower():
23+
print("Correct!")
24+
score += 1
25+
else:
26+
print("Wrong answer. Correct answer: " + riddles[riddle_key])
27+
28+
print("Game over! Your score is: " + str(score))

0 commit comments

Comments
 (0)