0

The code looks like this, it's code for one of those exercises to practice. The exercise was to generate a number and then prompt the user to guess the randomly generated number:

import random
x = 0
a = random.randint(1,9)
b = input("User's guess of the number generated: ")
def turn():
    x += 1
    if b < a:
        print("The number was too low.")
    elif b == a:
        print("You got the number right")
        break
    else:
        print("The number was too high")

while x != 3:
    turn()
    quit()
Urxtixt
  • 29
  • 1
  • 5
  • 1
    Well… there's no loop. So `break` doesn't make sense. – deceze Mar 08 '21 at 13:55
  • 2
    `break` can't break a loop that's behind a function call. Imagine you were calling some function from a loop, and suddenly _your_ loop terminates because that function executed `break`. And you have no control over that function because it's from a library. Now you have no way of running that function in a loop. – ForceBru Mar 08 '21 at 13:55
  • Note that `b` is a string, so you will want to `int` or `float` it. – astrochun Mar 08 '21 at 13:55
  • You'll encounter an `UnboundLocalError` next… https://stackoverflow.com/q/370357/476 – deceze Mar 08 '21 at 13:58

0 Answers0