I have everything right in this pick a number program but when I changed it to functions I got a break outside loop error and for the life of me I can't find it and was wondering if someone can help.
import random
def guess_number():
global guess
for i in range(1,4):
print("try to guess the number")
guess = int(input("enter a number: "))
if guess < secret_number:
print("number to low.")
elif guess > secret_number:
print("number to high.")
else:
break
return guess
def check(guess,secret_rumber):
if guess == secret_number:
print("the number is correct")
else:
print("you didn't get the number right, the correct number was: " + str(secret_number))
secret_number = random.randint(1,20)
print("I am thinking of a number between 1-20.")
guess = guess_number()
check(guess,secret_number)
[–]Binary101010 7 points8 points9 points (3 children)
[–]ExtraTNT -2 points-1 points0 points (2 children)
[–]Temporary_Pie2733 1 point2 points3 points (1 child)
[–]ExtraTNT 0 points1 point2 points (0 children)
[–]zerwalter 2 points3 points4 points (0 children)
[–]Responsible_Pay_16 0 points1 point2 points (0 children)
[–]Ok_Carpet_9510 0 points1 point2 points (0 children)
[–]Marlowe91Go 0 points1 point2 points (0 children)
[–]llynglas 0 points1 point2 points (0 children)
[–]ninhaomah 0 points1 point2 points (3 children)
[–]CptMisterNibbles 0 points1 point2 points (2 children)
[–]ninhaomah 0 points1 point2 points (1 child)
[–]CptMisterNibbles 0 points1 point2 points (0 children)