guess the word python

import random
# Put words to guess inside the array 
words = []
 
word = random.choice(words)
n = len(word)
 
print("Guess the word")

guesses = ''
#number of turn is equal to the legnth of the word stored in 'n'
turns = n
 
 
while turns > 0:
     
    #counts the number of wrong choices
    failed = 0
    
    for char in word:
        if char in guesses:
            print(f"\t{char}")
        else:
            print(f"\t_")
            failed += 1
             
 
    if failed == 0:
        print("Congratulations! you Win!\n")
        print(f"The word is: {word}")
        break
     

    guess = input("\nguess a letter: ")
    guesses += guess
     
    #decrements the turns for every wrong guess
    if guess not in word:
        turns -= 1
        print("Wrong")
        print(f"You have, {turns} more guesses")

        if turns == 0:
            print(f"You Loose, The word is {word}.")

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source