-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHangman.py
More file actions
37 lines (35 loc) · 780 Bytes
/
Hangman.py
File metadata and controls
37 lines (35 loc) · 780 Bytes
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
import sys
import os
noOfWords = len(sys.argv)
if noOfWords == 1:
print ("\tPlease enter the movie name")
sys.exit()
else:
movie1 = sys.argv
movie1.remove('Hangman.py')
movie = " ".join(movie1)
print ("Hi")
print (movie1)
print (movie)
os.system("clear")
allowed_attempts = 7
guessed_char = ' '
while allowed_attempts > 0:
mistake = 0
for letter in movie:
if letter in guessed_char:
print (letter)
else:
print ('\b'+ '_')
mistake = mistake + 1
if mistake == 0:
print ('Well Done')
break
guess = input('Take your guess: ')
guessed_char += guess
if (guess not in movie) and (allowed_attempts > 0):
allowed_attempts = allowed_attempts - 1
print ('Attempts left: '+ str(allowed_attempts))
if allowed_attempts == 0:
print ('Game over')
break