Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 wont print last sentence..
#1
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?
buran wrote Jan-27-2019, 04:18 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Quote
#2
If you're running this is command line, it will print "you win" and immediately break ending the program. Run it in IDLE.
Quote
#3
#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')
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  how to get all the possible permutation and combination of a sentence in python sodmzs 1 306 Jun-13-2019, 07:02 AM
Last Post: perfringo
  Sentence maker help bidoofis 2 430 Feb-08-2019, 03:59 AM
Last Post: bidoofis
  Generating all simple sentence possibilities Max_77 3 693 Oct-10-2018, 11:35 AM
Last Post: Max_77
  PigLatin Sentence Translator Help 2skywalkers 7 1,514 Jun-23-2018, 12:46 AM
Last Post: 2skywalkers

Forum Jump:


Users browsing this thread: 1 Guest(s)