0

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.

2
  • 2
    You get the input from the user, convert it to an integer and then throw it away. That can't work. Store the result in the variable instead. Commented Apr 18, 2022 at 17:28
  • @Parisa.H.R I rolled back your edit because it made the post worse. There is no reason to use code fences for "Python 3.9.12". Commented Apr 18, 2022 at 17:32

1 Answer 1

2
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.

Sign up to request clarification or add additional context in comments.

1 Comment

Duh, I knew it was simple. I figure out how I got confused as well. When I watched the video that had this code and I guess I didn't realize what they were doing. print('something') data = input() print('something ' + data) Thanks so much for your help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.