为什么这个for循环不能打印此列表/数组中的所有内容?例如,列表sentence
的值为[0, 2]
,但只打印出0
# this variable is global, meaning it can be used everywhere.
numbers = []
def looping(number, increment):
i = 0
while i < number:
print "At the top of i is %d" % i
numbers.append(i)
i = i + increment
print "Numbers now: ", numbers
print "At the bottom of i is %d" % i
looping(2, 2)
print "The numbers: "
for num in numbers:
print num
答案 0 :(得分:1)
您需要while i <= number:
而不是while i < number: