虽然循环数字似乎不起作用
While loop over numbers doesn't seem to be working
我是 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)
你输入的是字符串类型,但是比较器
while i < loop:
期望 i 和 loop 都是 int 类型(对于整数),以便能够比较它们。
您可以通过将循环转换为 int 来解决此问题:
def whilelooper(loop):
i = 0
numbers = []
loop = int(loop)
...
我是 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)
你输入的是字符串类型,但是比较器
while i < loop:
期望 i 和 loop 都是 int 类型(对于整数),以便能够比较它们。
您可以通过将循环转换为 int 来解决此问题:
def whilelooper(loop):
i = 0
numbers = []
loop = int(loop)
...