def get(i, x):
i = 0
numbers = []
while i < x:
print ('At the top i is %d' % (i))
numbers.append(i)
i = i + 1
print ("Numbers now: "), numbers
print ("At the bottom i is %d" % (i))
print ("The numbers: ")
for num in numbers:
print (num)
get(1,6)
所以当我调用函数时,这就是结果:
At the top i is 0
Numbers now:
At the bottom i is 1
At the top i is 1
Numbers now:
At the bottom i is 2
At the top i is 2
Numbers now:
At the bottom i is 3
At the top i is 3
Numbers now:
At the bottom i is 4
At the top i is 4
Numbers now:
At the bottom i is 5
At the top i is 5
Numbers now:
At the bottom i is 6
The numbers:
0
1
2
3
4
5
为什么"Numbers now: "
没有显示任何内容? print
语句,append
函数或其他内容是否有问题?我迷失在这里,感谢任何帮助。
答案 0 :(得分:2)
您需要在print语句中包含括号内的numbers
。
print ("Numbers now: ", numbers)
代替print ("Numbers now: "), numbers