Python Forum
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?
Reply
#2
If you're running this is command line, it will print "you win" and immediately break ending the program. Run it in IDLE.
Reply
#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')
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Why wont this path work one way, but will the other way? cubangt 2 623 Sep-01-2023, 04:14 PM
Last Post: cubangt
  while sentence kimyyya 3 2,905 Mar-20-2021, 06:00 AM
Last Post: Pedroski55
  List / arrays putting in sentence Kurta 3 2,514 Dec-25-2020, 11:29 AM
Last Post: Larz60+
  How to make a telegram bot respond to the specific word in a sentence? Metodolog 2 6,271 Dec-22-2020, 07:30 AM
Last Post: martabassof
  How to match partial sentence in long sentence Mekala 1 1,486 Jul-22-2020, 02:21 PM
Last Post: perfringo
  Remove a sentence if it contains a word. lokhtar 6 5,773 Feb-11-2020, 04:43 PM
Last Post: stullis
  Regex Help for clubbing similar sentence segments regstuff 3 2,113 Nov-20-2019, 06:46 AM
Last Post: perfringo
  When I import a Module it wont run PyNovice 17 6,241 Oct-26-2019, 11:14 AM
Last Post: PyNovice
  how to get all the possible permutation and combination of a sentence in python sodmzs 1 4,121 Jun-13-2019, 07:02 AM
Last Post: perfringo
  Why wont this work? ejected 2 3,140 Mar-29-2019, 05:33 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020