'Python input breaking if statement

I am using Python 3.9.12. I am doing a program where you input number of borders around your country. If you don't have any borders around your country you print(No border), elif have one country print(only 1 border) else print(more than 1 border.

Problem: I can't get the input to print the correct output. If I comment out the input and just insert the number in number_of_neighbours like this it will work:

number_of_neighbours = 0
number_of_neighbours = int(number_of_neighbours) 
if number_of_neighbours  == 0:
    print('No borders')
elif number_of_neighbours  == 1:
    print('Only 1 border!')
else: 
    print('More than 1 border!')

But I want to use the input like this, but it does not work. I have read and watched stuff to I am blue in the face, but I am missing one thing and I don't know what it could be. I have been working for two days on this.

number_of_neighbours = 0
int(input('How many neighbouring countries does your country have?'))
number_of_neighbours = int(number_of_neighbours) 
if number_of_neighbours  == 0:
    print('No borders')
elif number_of_neighbours  == 1:
    print('Only 1 border!')
else: 
    print('More than 1 border!')

Any help and explanation will be greatly appreciate.



Solution 1:[1]

number_of_neighbours = int(input('How many neighbouring countries does your country have?'))
if number_of_neighbours  == 0:
    print('No borders')
elif number_of_neighbours  == 1:
    print('Only 1 border!')
else: 
    print('More than 1 border!')

You need to assign the input to a variable.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 JadenJin