python while loop

im making a word guessing game and the guess will be the input and the word will be generated if the guess=word,then i want the program to print that we got the number,but if the guess is not equal to word then how do u make the program to run from the point where the user inputs the guess?.pls help me

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi @anandu4115,

You can try something like the following

import random
#List of Words
wordsinrandom = ['Melon','Apple', 'Orange', 'Banana',]

#Take a random world from that list
randomWORD = random.choice(wordsinrandom)

#Make game active
game_active = True

#While game is active you'll always be in this loop
while game_active:
    userGuess = input('Please enter the Fruit in my mind: ')

    # If the user's guess is correct, stop the game
    if userGuess == randomWORD :
        game_active = False
    #Wrong guess, try again
    print('No luck! Please try again')

print('Congratulations you guessed the fruit')

Regards, KFSys