[Tutor] Help!

Fredrick Barrett f.barrett12 at gmail.com
Sat May 16 01:35:30 CEST 2015


Hi, I'm a beginner and I've reached a roadblock. I'm trying to create a
simple guessing game program just to practice creating loops, however it is
not working out as planned.

print ("Lets play a game")

import random

# Generate random number from 1-10
rand_value = random.randint(1,10)
guess = input("Guess a number from 1-10 ")

if guess == rand_value:
    print ("Congratulations! You guessed it!")
while guess != rand_value:
    input ("try again")
else:
    print ("Sorry, you're wrong.")


input ("\n\nBetter luck next time. Press the enter key to exit.")

The goal is for the program to keep running until someone successfully
guesses the right number, however I think I've accidentally created an
infinite loop. Any help will be greatly appreciated.


More information about the Tutor mailing list