bigger and smaller between 2 numbers in a row problem [closed]

I am trying to make a guessing game , when I run it it is run correctly but when I guess its make it bigger and smaller between 2 numbers in a row:

from random import randrange
#variables
num1 = int(input('From: '))
num2 = int(input('To: '))

while True:
    user = randrange(num1, num2)
    ans = int(input('Enter your guess = '))
    
    if user == ans:
        print('You Win !n')
        break
    print('Smaller ' if (user < ans) else 'Bigger')

Answer

Initialize the number to guess (user) outside the while loop. Otherwise you’re guessing a different number at each iteration of the loop:

from random import randrange
#variables
num1 = int(input('From: '))
num2 = int(input('To: '))
user = randrange(num1, num2)

while True:
    ans = int(input('Enter your guess = '))
    if user == ans:
        print('You Win !n')
        break
    print('Smaller ' if (user < ans) else 'Bigger')