Skip to content

Commit 0fe0218

Browse files
committed
Create ex-22(Adventure).py
1 parent 3b0fada commit 0fe0218

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

ex-22(Adventure).py

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
def start_adventure():
2+
print("Welcome to the Adventure Game!")
3+
print("You find yourself at the entrance of a dark forest.")
4+
print("There are three paths ahead of you:")
5+
print("1. Take the left path.")
6+
print("2. Take the middle path.")
7+
print("3. Take the right path.")
8+
9+
choice = input("Choose your path (1, 2, or 3): ")
10+
11+
if choice == "1":
12+
left_path()
13+
elif choice == "2":
14+
middle_path()
15+
elif choice == "3":
16+
right_path()
17+
else:
18+
print("Invalid choice. Please try again.")
19+
start_adventure()
20+
21+
def left_path():
22+
print("\nYou chose the left path and encounter a hungry wolf!")
23+
print("What will you do?")
24+
print("1. Fight the wolf.")
25+
print("2. Run away.")
26+
action = input("Choose your action (1 or 2): ")
27+
28+
if action == "1":
29+
print("You bravely fight the wolf and emerge victorious!")
30+
print("Congratulations, you survived the adventure!")
31+
elif action == "2":
32+
print("You run away safely but miss out on the treasure hidden ahead.")
33+
else:
34+
print("Invalid choice. The wolf attacks you. Game over.")
35+
36+
def middle_path():
37+
print("\nYou chose the middle path and find a treasure chest.")
38+
print("It's locked. You see a note with a riddle:")
39+
print("What has keys but can't open locks?")
40+
answer = input("Your answer: ").strip().lower()
41+
42+
if answer == "piano":
43+
print("Correct! The chest opens, revealing gold and jewels!")
44+
print("Congratulations, you're rich!")
45+
else:
46+
print("Wrong answer. The chest remains locked forever. Game over.")
47+
48+
def right_path():
49+
print("\nYou chose the right path and fall into a hidden trap.")
50+
print("Unfortunately, you couldn't escape. Game over.")
51+
52+
# Start the game
53+
start_adventure()

0 commit comments

Comments
 (0)