Skip to content

Commit 658f743

Browse files
authored
Added Magic 8 ball game
1 parent c1d2d19 commit 658f743

File tree

1 file changed

+22
-71
lines changed

1 file changed

+22
-71
lines changed

magic8ball.py

+22-71
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,26 @@
1-
'''Author Anurag Kumar(mailtoanuragkumarak95@gmail.com)
2-
Module for implementing the simpest Magic 8 Ball Game.
3-
4-
Python:
5-
- 3.5
6-
7-
Requirements:
8-
- colorama
9-
10-
Usage:
11-
- $python3 magic8ball.py
12-
13-
Ask a question, and know the future.
14-
'''
15-
from random import randint
16-
from time import sleep
17-
18-
from colorama import Fore, Style
19-
20-
# response list..
21-
response = [
22-
"It is certain",
23-
"It is decidedly so",
24-
"Without a doubt",
25-
"Yes, definitely",
26-
"You may rely on it",
27-
"As I see it, yes",
28-
"Most likely",
29-
"Outlook good",
30-
"Yes",
31-
"Signs point to yes",
32-
"Quite possibly so",
33-
"Ask again later",
34-
"Better not tell you now",
35-
"Cannot predict now",
36-
"Concentrate and ask again",
37-
"Don't count on it",
38-
"My reply is no",
39-
"My sources say no",
40-
"Outlook not so good",
41-
"Very doubtful"]
42-
43-
44-
# core game...
45-
def game():
46-
ques = str(input("What is your question? \n").lower())
47-
print("thinking...")
48-
sleep(1)
49-
idx = randint(0, 20)
50-
if idx < 10:
51-
color = Fore.GREEN
52-
elif idx >= 10 and idx < 15:
53-
color = Fore.YELLOW
1+
import random
2+
3+
responses = ['It is certain','It is decidedly so','Without a doubt','Yes definitely ','You may rely on it','As I see it, yes','Most likely ','Outlook good','Yes','Signs point to yes','Do not count on it','My reply is no',' My sources say no',' Outlook not so good','Very doubtful', 'Reply hazy try again','Ask again later','Better not tell you now ','Cannot predict now ','Concentrate and ask again']
4+
print("Hi! I am the magic 8 ball, what's your name?")
5+
name = input()
6+
print("Hello!"+ name)
7+
8+
def magic8Ball():
9+
print("Whay's your question? ")
10+
question = input()
11+
answer = responses[random.randint(0,len(responses)-1)]
12+
print(answer)
13+
tryAgain()
14+
15+
16+
def tryAgain():
17+
print("Do you wanna ask any more questions? press Y for yes and any other key to exit ")
18+
x = input()
19+
if(x == 'Y'):
20+
magic8Ball()
5421
else:
55-
color = Fore.RED
56-
print(color + response[idx] + Style.RESET_ALL + '\n\n')
57-
playloop()
58-
22+
exit()
5923

60-
# looping func...
61-
def playloop():
62-
ques_again = str(input("Would you like to ask another question? (y/n)\n").lower())
63-
if ques_again == 'y':
64-
game()
65-
66-
elif ques_again == 'n':
67-
print("Auf Wiedersehen!")
68-
69-
else:
70-
print("What was that?/n")
71-
playloop()
7224

7325

74-
if __name__ == '__main__':
75-
game()
26+
magic8Ball()

0 commit comments

Comments
 (0)