提供字符串输入并将它们存储在没有数量限制的列表中
giving string inputs and store them in a list without number limitation
我在编程方面有点菜鸟。我想将我的日常学习主题保存在一个列表中,我的代码有主题数量限制(在范围(3)内)但是我不知道如果没有数字 limitation.Any 建议怎么办?
topics = []
for todays_topic in range(3):
topics.append(input("inter here>> "))
print(topics)
我不确定你的问题,但我猜你想不断地将你的 todays_topic 添加到你的列表中,直到你想停止。最好使用 while 循环而不是 for 循环。使用 while True
并继续添加元素。取一个变量,询问是否要输入更多。如果是则继续,如果否则中断循环。您的代码:
topics=[]
while True:
todays_topic=input("Enter here>> ")
topics.append(todays_topic)
asc=input("Enter more?? Y/N: ")
if asc=="N"
break
我在编程方面有点菜鸟。我想将我的日常学习主题保存在一个列表中,我的代码有主题数量限制(在范围(3)内)但是我不知道如果没有数字 limitation.Any 建议怎么办?
topics = []
for todays_topic in range(3):
topics.append(input("inter here>> "))
print(topics)
我不确定你的问题,但我猜你想不断地将你的 todays_topic 添加到你的列表中,直到你想停止。最好使用 while 循环而不是 for 循环。使用 while True
并继续添加元素。取一个变量,询问是否要输入更多。如果是则继续,如果否则中断循环。您的代码:
topics=[]
while True:
todays_topic=input("Enter here>> ")
topics.append(todays_topic)
asc=input("Enter more?? Y/N: ")
if asc=="N"
break