-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
93 lines (88 loc) · 1.86 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
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
import os
import sys
import random
types = ["""
____
| |
|
|
|
|_______
""", """
____
| |
| O
|
|
|_______
""", """
____
| |
| O
| |
|
|_______
""", """
____
| |
| O
| /|
|
|_______
""", """
____
| |
| O
| /|\\
|
|_______
""", """
____
| |
| O
| /|\\
| /
|_______
""", """
____
| |
| O
| /|\\
| / \\
|_______
"""]
turn = 1
print('Welcome to scramble hangman.')
word_to_guess = input('Input the guessing word or type 1 for random word: ')
if word_to_guess == '1':
word_to_guess = random.choice(['monkeys', 'chicken', 'banana', 'jazz'])
guessed_letters = ["_"] * len(word_to_guess)
correctly_guessed_letters = []
while "_" in guessed_letters:
guess = input("Guess a letter: ")
if len(guess) != 1: # fixed the if statement
print('You may only guess one letter at a time.')
sys.exit()
if guess in correctly_guessed_letters:
print('You have already guessed this letter.')
continue # continue the while loop if letter was already guessed
if guess in word_to_guess:
correctly_guessed_letters.append(guess)
for i in range(len(word_to_guess)):
if word_to_guess[i] == guess:
guessed_letters[i] = guess
print(types[turn])
print('Correct guess.')
print('Correctly guessed letters: ' + ''.join(correctly_guessed_letters))
else:
turn = turn + 1
if turn == 6:
print(types[6])
print('You guessed wrong too many times!')
sys.exit()
else:
print(types[turn])
print("Incorrect guess.")
print('Correctly guessed letters: ' + ''.join(correctly_guessed_letters))
os.system('cls') # clear the screen after each guess
print("Congratulations! You guessed the word:", "".join(guessed_letters))