im making a word guessing game and the guess will be the input and the word will be generated randomly.so 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
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!
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')
# END
print('Congratulations you guessed the fruit')
Regards, KFSys
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.