-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGuessTheMovieName.py
104 lines (90 loc) · 3.54 KB
/
GuessTheMovieName.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import random as random
movies=['drishyam','nayakan','avengers','pink','golmaal','vikram vedha','black friday','dangal','manichithratazu','taare zameen par']
def createQues(movie):
n = len(movie)
letters = list(movie)
temp = []
for i in range (n):
if letters[i]==' ':
temp.append(' ')
else:
temp.append('-')
separator = ''
qn = separator.join(temp) #converts back to string
return qn
def isPresent(letter,movie):
return letter in movie
def unlock(question, movie, letter):
question = list(question)
for i in range(len(movie)):
if movie[i] == letter:
question[i] = letter
return ''.join(question)
def play():
p1name = input('Player 1 enter your name: ')
p2name = input('Player 2 enter your name: ')
pointsP1=0
pointsP2=0
turn=0
willing=True
while(willing is True):
if turn%2==0:
print(p1name," Your Turn")
pickedMovie = random.choice(movies)
question = createQues(pickedMovie)
print(question)
notSaid = True
while(notSaid):
letter = str(input("Your letter: "))
if(isPresent(letter,pickedMovie)):
modifiedQues = unlock(modifiedQues,pickedMovie,letter)
print(modifiedQues)
d = int(input('Press 1 to guess the movie name or 2 to nlock another letter'))
if d==1:
ans = input('Your answer: ')
if ans == pickedMovie:
pointsP1 = pointsP1+1
print('Correct')
notSaid = False
print(p1name,'Your score : ', pointsP1)
else:
print('Try again')
else:
print(letter," is not found")
c = int(input("Press 1 to continue or 0 to exit"))
if c==0:
print(p1name,'Your score is ',pointsP1)
print(p2name,'Your score is ',pointsP2)
print('Thanks for playing')
willing = False
else:
print(p2name," Your Turn")
pickedMovie = random.choice(movies)
question = createQues(pickedMovie)
print(question)
notSaid = True
while(notSaid):
letter = input("Your letter")
if(isPresent(letter,pickedMovie)):
modifiedQues = unlock(modifiedQues,pickedMovie,letter)
print(modifiedQues)
d = input('Press 1 to guess the movie name or 2 to nlock another letter')
if d==1:
ans = input('Your answer: ')
if ans==pickedMovie:
pointsP2=pointsP2+1
print('Correct')
notSaid=False
print(p2name,'Your score : ',pointsP2)
else:
print('Try again')
else:
print(letter," is not found")
c = input("Press 1 to continue or 0 to exit")
if c==0:
print(p1name,'Your score is ',pointsP1)
print(p2name,'Your score is ',pointsP2)
print('Thanks for playing')
willing = False
turn=turn+1
play()