在python中写入列表中的字符串输入
每次我按回车键都会显示我在python中写入列表中的字符串输入,python,python-3.x,Python,Python 3.x,每次我按回车键都会显示我 [] none 我不知道为什么,我想写数字6,而不是把它作为一个参数传递。在我写任何东西之前,不要接受这个问题,但是我写了所有我知道的东西,顺便说一下,我使用毕达姆 我想要这样的输出 6 baraclona madrid spain africa USA UAE 代码 您的程序中有许多问题。以下是其中一些: 您传入count,但在循环中使用test input()返回一个str,但可以将其用作int。需要进行转换 循环的典型计数类似于范围内i的(计数)。需要调
[]
none
我不知道为什么,我想写数字6,而不是把它作为一个参数传递。在我写任何东西之前,不要接受这个问题,但是我写了所有我知道的东西,顺便说一下,我使用毕达姆
我想要这样的输出
6
baraclona
madrid
spain
africa
USA
UAE
代码
您的程序中有许多问题。以下是其中一些:
- 您传入
,但在循环中使用count
test
返回一个input()
,但可以将其用作str
。需要进行转换int
- 循环的典型计数
类似于范围内i的
。需要调用(计数)
range()
- 没有
语句的函数隐式返回return
。需要一个None
返回输入
def OutputMostPopularDestination( ):
test = int(input("How many lines?"))
inputs =[]
for i in range(test):
string_input = input()
inputs.append(string_input)
return inputs
print(OutputMostPopularDestination())
你的程序有几个地方出了问题。请阅读并跟随全文。完成后,您将能够无误地编写此程序。您是@Rob先生,我将再次阅读教程,谢谢
def OutputMostPopularDestination( ):
test = int(input("How many lines?"))
inputs =[]
for i in range(test):
string_input = input()
inputs.append(string_input)
return inputs
print(OutputMostPopularDestination())