抱歉,如果您觉得这很愚蠢,但我对 LPTH 的练习 33 有疑问
http://www.learnpythonthehardway.org/book/ex33.html
Zed 要求我们:重写该练习以改用 for 循环和范围。你还需要中间的增量器吗?如果你不摆脱它会发生什么?
我这样做了:
numbers = []
def NumbersLoop(x):
"""
This function will loop as long as x is less than the limit,
at the same time it will print the numbers list
"""
limit = int(input('Limit: '))
increment = int(input('Increment: '))
for i in (x, limit):
print('At the top x is : {}'.format(x))
numbers.append(x)
x += increment
print('Numbers now: ', numbers)
print('At the bottom x is {}'.format(x))
NumbersLoop(1)
print('The numbers: ')
for num in numbers:
print(num)
但我不明白为什么它只循环到 3。还有可能摆脱中间的增量器吗?我看没有办法做到这一点...