coredarkness
coredarkness

Reputation: 15

Why is the while loop unable to break?

answer = 5
guess = int(input('Please make a wild number guess: '))
count = 1

while guess != answer:
    count += 1
    int(input('wrong. Please make another guess: '))
    print(f"this is your {count} attempt") 

    if guess == answer:
        break
        print('Correct!!!')

i didn't get the answer i expected after i typed 5. i am still stucked in the while loop after typing the correct answer.

wrong. Please make another guess: 5 this is your 6 attempt

Upvotes: 1

Views: 43

Answers (2)

SimpleNiko
SimpleNiko

Reputation: 107

As @Soulfly mentioned, you need to update guess.

Also, I suggest changing:

 if guess == answer:
        break
        print('Correct!!!')

to

 if guess == answer:
        print('Correct!!!')
        break

So the loop won't break before outputting the print statment.

Upvotes: 0

Soulfly
Soulfly

Reputation: 324

because you are not updating the value of "guess" inside your while loop, change it to be

guess = int(input('wrong. Please make another guess: '))

Upvotes: 3

Related Questions