-
Notifications
You must be signed in to change notification settings - Fork 0
/
Python_Magic_8_Ball_Game-01.py
40 lines (28 loc) · 1.07 KB
/
Python_Magic_8_Ball_Game-01.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
29
30
31
32
33
34
35
36
37
38
39
40
#import modules
import random,sys,csv
#class
class magic8ball:
def __init__(self ,name):
self.__name= name
self.__mquestions = []
self.__start_game()
def __start_game(self):
mresponse =["It is certain","You may rely on it","As I see it ,yes","It is decidedly so","Without a doubt","Yes deifintely","Yup","Of course"]
lQuestions= True
print("Welcome " + self.__name)
while lQuestions :
mQues = input("Please enter a question: ")
mRespond = mresponse[random.randint(0,7)]
if mQues =="":
print("Thank you for playing")
self.__write_questions()
sys.exit()
else :
print(mRespond)
self.__mquestions.append(mQues)
def __write_questions(self):
f = open("magic_questions.csv" ,"a", newline="")
wrt = csv.writer(f)
for q in self. __mquestions:
wrt.writerow([q])
f.close()