我正在编写一些代码来完成这个任务:用从0到9的数字填充数组,然后将小于5的数组放在数组的末尾。我的代码是:
print ("give n: ")
n = int(input())
a = []
for i in range(n):
num = 0
print ("give a number from 0 to 9 ")
num = int(input())
while (num > 9 and num < 0):
print ("only from 0 to 9")
num = int(input())
a.append(num)
tmp = 0
for i in range(n):
if (a[i]<5):
tmp = a[i]
a[i] = a[i+1]
a[i+1] = tmp
for i in range(n):
print a[i]我的问题是,当我运行它时,如果我给出任何其他信息并将它传递给数组,那么检查一个数字是否为0到9的循环就会被忽略,并且它会在第16行(ai = ai+1)上给出一个错误。提前感谢!
发布于 2015-02-23 14:17:06
用于在Python中进行调试。添加import pdb,然后将pdb.set_trace()放在希望调试器中断的位置。
发布于 2015-02-23 14:09:35
有用于python的调试器:https://docs.python.org/3/library/pdb.html在一开始学习它可能很有用。
https://stackoverflow.com/questions/28675495
复制相似问题