I'm begging learn programming that is first code of python I wrote . well this is a guess game,if user type a number 5 wil print" you won " ,if it greater than 5 print " toohigh ", and if smaller than 5 print " too low ".
I wrote the code for that but when the user input number 5, it print " too low " and print " you won " that is not I want, when input number 5 which is supposed to output message "You won". I need explain for why the output of code say "too low" and say "You won" with user input 5 number??
print("Welcome")
guess = 0
while guess != 5:
g = input("Guess a number: ")
guess = int(g)
if guess > 5:
print("too high")
else:
print("too low")
print("You won")
The result is :
Guess a number: 4
too low
Guess a number: 6
too high
Guess a number: 5
**too low // this isn't supposed to be, this is wrong
You won**