I need to implement my own version of the classic hangman game with greek letters.
I have tried to alter my code several times, however it seems that I have a problem managing all the ''if'' and ''else'' statements together. My main problem is that I cannot properly set the new word for the user to see every time his guess is correct(get_word function). Here is my code:
import random
words=['''list of greek words''']
greek_alphabet=['''list of all greek letters''']
def shape(left=5):
if left==5:
print('|----------|')
print('| O')
print('|')
print('|')
print('|')
print('|')
print('|')
elif left==4:
print('|----------|')
print('| O')
print('| /|\\')
print('|')
print('|')
print('|')
print('|')
elif left==3:
print('|----------|')
print('| O')
print('| /|\\')
print('| |')
print('|')
print('|')
print('|')
elif left==2:
print('|----------|')
print('| O')
print('| /|\\')
print('| |')
print('| _/ \\_')
print('|')
print('|')
elif left==1:
print('|----------|')
print('| O')
print('| /|\\')
print('| |')
print('| _/ \\_')
print('| ## ##')
print('|')
else:
print('|----------|')
print('| O')
print('| /|\\')
print('| |')
print('| _/ \\_')
print('| ## ##')
print('| fire')
def get_word(random_word,letter):
for i in random_word:
if i==letter:
new_word.replace('_ ',letter)
return new_word
def hangman():
found=False
random_word=random.choice(words)
words.remove(random_word)
used_letters=[]
max_guesses=0
incorrect_guesses=0
new_word=len(random_word)*'_ '
print('You can make up to 5 mistakes')
print('The 6th mistake is going to get you out of the game')
print('The word you must guess is: ',new_word)
while not found and incorrect_guesses<max_guesses:
letter=input('Give letter: ')
if found_word(random_word,new_word):
print('Congrats! You found the word!')
found=True
elif letter in random_word and letter not in used_letters:
used_letters.append(letter)
print('The word you must guess is',get_word(random_word,letter))
elif letter not in greek_alphabet:
print('You did not give a letter. Try again.')
elif letter in used_letters:
print('This letter has already been used')
else:
incorrect_guesses+=1
left=max_guesses-incorrect_guesses
shape(left)
print('You still have ',max_guesses-incorrect_guesses,'lives')
print('The word you must choose is ',get_word(random_word,letter))
if not found:
shape()
print('You did not find the word')
print('The word we were looking for was ',random_word)
return False
else:
return True
def found_hidden_word(random_word,new_word):
if new_word==random_word:
return True
hangman()
I have tried really hard to even get to that point, because I am an absolute beginner to this, however I believe that with some changes, my code is going to work properly.
May I suggest the following as a starting point? Please note that you will need to supply your own
words.txt
file with one Greek word per line. Once that file is in the same directory, this program should work fine: