import random

def get_user_guess():
    while True:
        try:
            guess = int(input(f"Guess the number (between {start} and {end}): "))
            if start <= guess <= end:
                return guess
            else:
                print(f"Invalid guess. Please enter a number between {start} and {end}.")
        except ValueError:
            print("Invalid input. Please enter a valid number.")
start = int(input("Enter the starting number: "))
end = int(input("Enter the ending number: "))
random_number = random.randint(start, end)
while True:
    user_guess = get_user_guess()

    if user_guess == random_number:
        print("Congratulations! You guessed the number correctly.")
        break
    else:
        print("Wrong guess. Try again!")
