-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
121 lines (83 loc) · 2.75 KB
/
app.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import random
from prettytable import from_csv
from msg import *
def hangman():
words = []
try:
with open('animals.txt', 'r') as file:
words = list(file.readlines())
main_word = random.choice(words).strip().upper()
word = main_word
guess = '_' * len(word)
word = list(word)
guess = list(guess)
user_guess = []
count = 1
usr_letter = input('\nGuess Letter: ').upper()[0:1]
cond = True
while cond:
if usr_letter in user_guess:
usr_letter = ''
print('Already Guess!')
if count <= (len(word) + 4):
usr_letter = input('Guess Letter: ').upper()[0:1]
count += 1
else:
gameover(main_word)
get_info('Lose', main_word)
cond = False
else:
print(''.join(guess))
if usr_letter in word:
index = word.index(usr_letter)
guess[index] = usr_letter
word[index] = '_'
else:
user_guess.append(usr_letter)
if count <= (len(word) + 4):
usr_letter = input('Guess Letter: ').upper()[0:1]
count += 1
else:
gameover(main_word)
get_info('Lose', main_word)
cond = False
if '_' not in guess:
print(''.join(guess))
won()
get_info('Won', main_word)
cond = False
if cond == False:
usr_input = input(play_again).lower()[0:1]
if usr_input == 'y':
hangman()
elif usr_input == 'n':
main()
except FileNotFoundError:
print('Error: Animals Words File Not Found!')
username = ''
def main():
while True:
menu()
usr_input = input('Enter your Choice: ')
if '1' == usr_input:
hangman()
break
elif '2' == usr_input:
get_score()
elif '3' == usr_input:
print('\nExiting Hangman Game...')
break
else:
print('Invalid command! Try again...')
def score(username, result, word):
data = username.capitalize() +','+ word +','+ result +','+ date() +'\n'
with open('results', 'a') as file:
file.write(data)
def get_info(res, word):
username = input('Enter username: ')
score(username, res, word)
def get_score():
print('\nScore Board\n***********', end='\n')
with open('results.txt', 'r') as file:
print(from_csv(file))
main()