如何存储从for循环收集的信息并将其分配给具有计数迭代的变量?

时间:2015-10-09 18:16:59

标签: python

我正在创建一个程序,它将接受输入,并在列表中的输入周围输出打开和关闭html标记。显然,下面的代码只会打印上次运行count次时输入的最后一个输入。我猜想必须在每次传递期间根据count创建一个新变量。我该如何做到这一点?

runNum = int( input( "How many items are you entering? : "))
print ("Type 1 if you would like to use the li tag or type 2 for the th tag")
descVar = input("")
if descVar == "1":
    for count in range ( 1, runNum + 1):
        print ("Please enter item #", count, "")
        item = input()


    for count in range (1, runNum):
        print ( <li>, item, </li> )

1 个答案:

答案 0 :(得分:0)

只需在列表中收集输入:

items = []
for count in range ( 1, runNum + 1):
        print ("Please enter item #", count, "")
        item = input()
        items.append(item)

for item in items:
        print ("<li>",item,"</li>")