Skip to content

Commit 64715d7

Browse files
authored
Update magic8.py
1 parent 95ff43d commit 64715d7

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import random
2+
3+
responses = [
4+
"Yes, definitely.",
5+
"As I see it, yes.",
6+
"Reply hazy, try again.",
7+
"Cannot predict now.",
8+
"Do not count on it.",
9+
"My sources say no.",
10+
"Outlook not so good.",
11+
"Very doubtful."
12+
]
13+
14+
def magic_8_ball():
15+
print("Welcome to the Magic 8 Ball! Ask a yes/no question.")
16+
17+
while True:
18+
question = input("Ask your question (or type 'quit' to exit): ")
19+
20+
if question.lower() == 'quit':
21+
print("Thanks for playing! Goodbye!")
22+
break
23+
24+
if question.strip() == "":
25+
print("Please ask a valid question.")
26+
continue
27+
28+
# Get a random response
29+
answer = random.choice(responses)
30+
print("Magic 8 Ball says:", answer)
31+
32+
# Run the program
33+
magic_8_ball()

0 commit comments

Comments
 (0)