I want my code to be repeated until the player guesses correctly.
ghuess=input("state a number between 1-100")
if ghuess>number:
print "
This is normally approached with a while
loop:
while True:
... # do your thing
if finished: # are we done here?
break # leave
... # execution resumes here after break
For a solution without a break
:
isFound = False
while not isFound:
ghuess=input("state a number between 1-100")
if ghuess>number:
print "too high try again!"
elif ghuess<number:
print "too low try again!"
else:
isFound = True
print "well done! ghuess you have won.."
time.sleep(1)
print "3"
time.sleep(1)
print "2"
time.sleep(1)
print "1"
time.sleep(1)
print prize
Add a while-loop there. This means you're looping the question again infinitely until you've reached a satisfactory result.
while True:
ghuess=input("state a number between 1-100")
if ghuess>number:
print "too high try again!"
elif ghuess<number:
print "too low try again!"
else:
# Jackpot, exit the loop.
break
print "well done! ghuess you have won.."
time.sleep(1)
print "3"
time.sleep(1)
print "2"
time.sleep(1)
print "1"
time.sleep(1)
print prize