我正在使用Python 3.9.12。我正在做一个程序,你在你的国家周围输入的边界数目。如果在您的国家周围没有任何边框,则打印(无边界),elif有一个国家打印(只有一个边框)其他打印(超过一个边框)。
问题:我无法让输入打印正确的输出。如果我注释掉输入,然后像这样在number_of_neighbours中插入数字,它就能工作了:
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!')但是我想像这样使用输入,但是它不起作用。我读过和看过的东西,我的脸是蓝色的,但我错过了一件事,我不知道它会是什么。我已经为此工作了两天了。
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!')任何帮助和解释都将不胜感激。
发布于 2022-04-18 17:29:01
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!')您需要将输入赋值给变量。
https://stackoverflow.com/questions/71915040
复制相似问题