Sep-21-2022, 03:26 AM
(This post was last modified: Sep-21-2022, 03:26 AM by monkeydesu.)
I've been teaching myself how to code for a few weeks and did a hangman game all by myself! I'm so chuffed ! Such a good feeling and I still can't believe it works!
I would love some tips about things to look out for, maybe something to clean the code a little? Be gentle as I'm new and super excited this all worked out haha
I would love some tips about things to look out for, maybe something to clean the code a little? Be gentle as I'm new and super excited this all worked out haha
import random
def making_a_guess():
x = 0
global update_display
correct_guess = False
for letter in chosen_word:
if guess.lower() == chosen_word[x]:
blank_list[x] = guess.lower()
correct_guess = True
x += 1
if correct_guess == False:
print(f"There is no {guess}, sorry.")
update_display += 1
x = 0
HANGMANPICS = ['''
+---+
| |
|
|
|
|
=========''', '''
+---+
| |
O |
|
|
|
=========''', '''
+---+
| |
O |
| |
|
|
=========''', '''
+---+
| |
O |
/| |
|
|
=========''', '''
+---+
| |
O |
/|\ |
|
|
=========''', '''
+---+
| |
O |
/|\ |
/ |
|
=========''', '''
+---+
| |
O |
/|\ |
/ \ |
|
=========''']
word_list = ["aardvark", "baboon", "camel", "jazz", "grass", "follow", "castle", "cloud"]
chosen_word = list(random.choice(word_list))
blank = ""
for letter in chosen_word:
blank += "_"
blank_list = list(blank)
update_display = 0
#----------------------------------------------------------------------------------------------
print(HANGMANPICS[update_display])
guess = input(f"Welcome to hangman.\n{blank}\nMake a guess? ")
making_a_guess()
print(HANGMANPICS[update_display])
print(''.join(blank_list))
while update_display < 6:
if blank_list == chosen_word:
print("YOU WIN!")
break
guess = input("Make another guess? ")
making_a_guess()
print(HANGMANPICS[update_display])
print(''.join(blank_list))
if update_display == 6:
print("GAME OVER.")
