我是python的新手,正在尝试运行这段代码,但是,while循环似乎无法正常工作。有什么想法吗?
def whilelooper(loop):
i = 0
numbers = []
while i < loop:
print "At the top i is %d" %i
numbers.append(i)
i += 1
print "numbers now:",numbers
print "At the bottom i is %d" %i
print "the numbers:",
for num in numbers:
print num
print "Enter a number for loop"
b = raw_input(">")
whilelooper(b)
答案 0 :(得分:2)
您的输入以字符串类型输入,但比较器
while i < loop:
期望i和loop都为int类型(对于整数),以便能够进行比较。
您可以通过将循环强制转换为int来解决此问题:
def whilelooper(loop):
i = 0
numbers = []
loop = int(loop)
...