100-Days OF Python-Day-07

                                          Python-Hangman Project:


For completing this project we will going through the below skills:


    For & While Loop:
    If/ELSE:
    Lists:
    Strings:
    Range:
    Modules:
    import random
    word_list=["Bottle","Rat","Mouse"]
    random_word1=random.choice(word_list)
    random_word=random_word1.lower()

    print(random_word)
    guess_word=input("Type a word:").lower()

    for i in random_word:
        if i==guess_word:
          print("Right")
        else:
            print("Wrong")

Important Note:

display=[]
display=display + "_"

The above code shows error

but this code does not display +="_"

As += is Augmented assignment and the below link of stack overflow will
define in more detail:





import random
End_of_game=False
print("Lets Play Hangman Game")
word_list=["mouse","lion","horse","donkey","ant","sachin","dravid"]
user_word=random.choice(word_list)
word_length=len(user_word)
lives=6
display=[]
i=0
for w in range(word_length):
    if w < word_length:
        display +="_"
        i=i+1



while not End_of_game:
    
    guess_word=input(f"enetr a word that matches the word {user_word}:").lower()
    for position in range(word_length):
        letter=user_word[position]
        if letter == guess_word:
            display[position]=letter

    
    if guess_word not in user_word:
        lives=lives-1
        if lives==0:
            End_of_game=True
            print("You lose")
        
        



    print(display)
    
    if "_" not in display:
        End_of_game=True
        print("You win.")

Comments

Popular posts from this blog

Top 5 Best Books For Python,Data Science & Machine Learning

How To Start A BLOG

Top 50 Most Innovative Companies in 2020

Why Should We learn C Programming?

Blogger Tutorial