Python Forum

Full Version: wont print last sentence..
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
import random
a = random.randint(1,99)
guess = int(input('et tal..'))
print
while a != guess:
    if guess < a:
        print('low..')
        guess = int(input('gæt igen..'))
    elif guess > a:
        print('high..')
        guess = int(input('gæt igen'))
    else:
        print('you win')
        break
it does not print 'you win', it just breaks out. Why is that?
If you're running this is command line, it will print "you win" and immediately break ending the program. Run it in IDLE.
#Put the last line outside the loop as when a equals guess the loop will break.
import random
a = random.randint(1,99)
guess = int(input('et tal..'))
print
while a != guess:
if guess < a:
print('low..')
guess = int(input('gæt igen..'))
elif guess > a:
print('high..')
guess = int(input('gæt igen'))
print('You win')