-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmovie_guess.py
More file actions
59 lines (57 loc) · 1.78 KB
/
movie_guess.py
File metadata and controls
59 lines (57 loc) · 1.78 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import random
class user:
def __init__(self):
self.movie=''
self.tries=5
self.clue=''
self.guess=[]
self.wrong=[]
self.display=''.join(self.guess)
def pick(self):
files=open('movie.txt','r')
file=files.readlines()
file=str(file)
file=file.split(',')
file=random.choice(file)
file=file.split(':')
movie=file[0]
clue=file[1]
self.movie=movie
self.movie_=list(self.movie)
self.clue=clue
for each in self.movie:
if each.isalnum()==True:
self.guess.append('-')
elif each==' ':
self.guess.append(' ')
self.display=''.join(self.guess)
return
def guesser(self):
print('Fill in the blanks to reveal the movie {} Type \'clue\' to ask for a clue.'.format(''.join(self.guess)))
guess=input(': ')
movie_=list(self.movie)
if guess in movie_:
print('Right choice!!')
posi=[c for c,elem in enumerate(self.movie)if elem==guess]
for i in posi:
self.guess[i]=guess
elif guess=='clue':
print('Clue:{}'.format(self.clue))
self.tries-=2
else:
print('there is no such letter here')
self.tries-=1
self.wrong.append(guess)
print('Tries Left: {}'.format(self.tries))
print('Wrong guesses:{}'.format(self.wrong))
if self.tries==0:
print('the name of the movie is {}'.format(self.movie))
return
def game(self):
self.pick()
while self.guess!=self.movie_ and self.tries>0:
self.guesser()
print("Congrats your movie is {}".format(self.movie))
return
a=user()
a.game()