-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuessTheMovieName
More file actions
121 lines (110 loc) · 3.88 KB
/
GuessTheMovieName
File metadata and controls
121 lines (110 loc) · 3.88 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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import random
movies=['anand','drishyam','nayakan','anbe sivam','gol maal','vikran vedha','black friday','dangal','manikarnika','tare zameen par']
def create_question(movie):
n=len(movie)
letters=list(movie)
temp=[]
for i in range(n):
if letters[i]==' ':
temp.append(' ')
else:
temp.append('*')
qn=''.join(str(x) for x in temp)
return qn
def is_present(letter,movie):
c=movie.count(letter)
if c==0:
return False
else:
return True
def unlock(qn,movie,letter):
ref=list(movie)
qn_list=list(qn)
temp=[]
n=len(movie)
for i in range(n):
if ref[i]==' ' or ref[i]==letter:
temp.append(ref[i])
else:
if qn_list[i]=='*':
temp.append('*')
else:
temp.append(ref[i])
qn_new = ''.join(str(x) for x in temp)
return qn_new
def play():
p1name=input("Player 1, Please enter your name ")
p2name=input("Player 2, Please enter your name ")
pp1=0
pp2=0
turn=0
willing=True
while willing:
if turn%2==0:
#player 1
print(p1name," Your turn ")
picked_movie=random.choice(movies)
qn=create_question(picked_movie)
print (qn)
modified_qn=qn
not_said=True
while not_said:
letter=input("Your letter : ")
if(is_present(letter,picked_movie)):
#unlock
modified_qn=unlock(modified_qn,picked_movie,letter)
print(modified_qn)
d=input("Press 1 to guess the movie or 2 to unlock another letter : ")
if d==1:
ans=input("Your answer : ")
if ans==picked_movie:
pp1=pp1+1
print("Coorect ")
not_said=False
print(p1name," Your score : ",pp1)
else:
print("Wrong answer. Try again.")
else:
print(letter," not found")
c=input("Press 1 to continue or 0 to quit")
if c==0:
print(p1name," Your score : ",pp1)
print(p2name," Your score : ",pp2)
print("Thanks for playing")
print("Have a nice day")
willing=False
else:
#player 2
print(p2name," Your turn ")
picked_movie=random.choice(movies)
qn=create_question(picked_movie)
print (qn)
modified_qn=qn
not_said=True
while not_said:
letter=input("Your letter : ")
if(is_present(letter,picked_movie)):
#unlock
modified_qn=unlock(modified_qn,picked_movie,qn)
print(modified_qn)
d=input("Press 1 to guess the movie or 2 to unlock another letter : ")
if d==1:
ans=input("Yur answer : ")
if ans==picked_movie:
pp2=pp2+1
print("Coorect ")
not_said=False
print(p2name," Your score : ",pp2)
else:
print("Wrong answer. Try again.")
else:
print(letter," not found")
c=input("Press 1 to continue or 0 to quit")
if c==0:
print(p1name," Your score : ",pp1)
print(p2name," Your score : ",pp2)
print("Thanks for playing")
print("Have a nice day")
willing=False
turn=turn+1
play()