Linked Questions

Popular Questions

Secret Word Game - Python

Asked by At

I'm starting to study programming now and I have to do a secret word game, but whenever I run the code the result is concatenated and it was supposed to appear only once, where am I going wrong? I'll paste the code and attach a screenshot of the console. I'm open to other tips and improvements.

print('¨' * 40)
print(f'|{"Secret Word Game":^38}|')
print('¨' * 40)

secret_word = 'believer'
user_input = ''
typed = []
attempts= 0
number_of_letters = '_ ' * len(secret_word)
discovering_secret_word = ''

print('Try to guess the Secret Word!')
print(f'The secret word is: {number_of_letters}')

while discovering_secret_word != secret_word:
    user_input = input('Type a letter: ')
    attempts += 1

    if len(user_input) > 1:
        print('You can´t insert more than one letter!')


    for letter in secret_word:
        if letter in typed:
            discovering_secret_word += letra
            discovering_secret_word += '_ '
    print(f'The Secret Word is {discovering_secret_word}')
    print('Congratulations, you won!')
    print(f'The Secret Word is {secret_word}.')
    print(f'It took {attempts} attempts.')


Related Questions