-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
67 lines (55 loc) · 1.64 KB
/
main.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
import random
from drawhangman import drawhangman
print("Welcome to Hangman!")
def listjoin(list):
string = ''.join(list)
return string
def loadnouns():
wordlist = ""
file = open("parsednouns.txt")
wordlist = file.read().splitlines()
print("Choosing word from list of " + str(len(wordlist) ) )
return wordlist
def menu():
start = input("\nType '1' and ENTER to start!")
if start == "1":
play()
return
else:
print("Sorry, I didn't catch that!")
menu()
return
def play():
wrongcount = 0
wordlist = loadnouns()
chosenword = list(random.choice(wordlist))
guess = ["_ "] * len(chosenword)
debugchosen = listjoin(chosenword).replace(" ", "")
guessed = []
while wrongcount < 6:
drawhangman(wrongcount)
print(listjoin(guess))
print("Current Guesses: " + str(guessed))
userinput = input("Guess a letter!")
if len(userinput) == 1:
if userinput in guessed:
print("You've already guessed that!")
guessed.remove(userinput)
wrongcount -= 1
guessed += userinput
for i in range (0,len(chosenword)):
if userinput == chosenword[i]:
guess[i] = userinput + " "
if userinput not in chosenword:
print("That's not in the word!")
wrongcount += 1
debugguess = listjoin(guess).replace(" ", "")
if debugguess == debugchosen:
print("Congratulations, you guessed the word: ")
menu()
if wrongcount >= 6:
drawhangman(wrongcount)
print("Oh no! you lose! the word was: ")
print(listjoin(chosenword))
menu()
menu()