1
我通過工作學習Python硬盤的方式,並在運動33加分2我想利用或者raw_input
或argv
設置將在while循環中使用的變量:爲什麼這個python while循環缺少邏輯運算符?
# from sys import argv
# script, my_num = argv
def all_the_numbers(n):
"""increment by 1 up to limit n"""
i = 0
numbers = []
while i < n:
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 "Please enter an integer: "
# n = raw_input("#")
# n = my_num
n = 10
all_the_numbers(n)
硬編碼n = 10
按預期工作;打印行數達到10
。但是從argv
傳入的值爲my_num
和/或從raw_input
設置變量會導致向上的無限整數遞增。後兩種設置變量的方式有什麼不同,它們的行爲並不完全像同一個變量的硬編碼設置?
謝謝,格雷格。這很有道理;儘管我並沒有懷疑它的結果是一個整體鏈的增加。 – gonzo 2011-03-30 05:24:23