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 171 Jun-13-2019, 07:02 AM
Last Post: perfringo
  Why wont this work? ejected 2 329 Mar-29-2019, 05:33 AM
Last Post: snippsat
  Variable defined but python wont recognize it. FWendeburg 3 373 Feb-19-2019, 10:43 PM
Last Post: woooee
  Sentence maker help bidoofis 2 298 Feb-08-2019, 03:59 AM
Last Post: bidoofis
  time.time wont return a useable number Nyscersul 4 460 Nov-15-2018, 03:08 PM
Last Post: Nyscersul
  Why wont this work :( Nonagon 2 399 Nov-03-2018, 03:38 AM
Last Post: wavic
  Generating all simple sentence possibilities Max_77 3 543 Oct-10-2018, 11:35 AM
Last Post: Max_77
  Python - Limit Sentence Length to 10 Words - Text file dj99 2 986 Jul-21-2018, 02:24 PM
Last Post: dj99
  python wont recognize indentation JWhykes 6 830 Jul-06-2018, 10:55 AM
Last Post: JWhykes
  PigLatin Sentence Translator Help 2skywalkers 7 1,270 Jun-23-2018, 12:46 AM
Last Post: 2skywalkers

Forum Jump:


Users browsing this thread: 1 Guest(s)