Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Error handling while循环中出现不支持的操作数类型错误_Error Handling - Fatal编程技术网

Error handling while循环中出现不支持的操作数类型错误

Error handling while循环中出现不支持的操作数类型错误,error-handling,Error Handling,我使用两个主要的while循环。一个用来输入的。其他用于运行测试 我得到了这个错误: Error : File "n1.py", line 22, in <module> while j<n-1 and line[a][j+1]-line[a][j]<=2: TypeError: unsupported operand type(s) for -: 'list' and 'int' 错误:文件“n1.py”,第22行,而j中的所有内容都不是整数。在第3行你有n=[

我使用两个主要的while循环。一个用来输入的。其他用于运行测试

我得到了这个错误:

Error : File "n1.py", line 22, in <module>    while j<n-1 and line[a][j+1]-line[a][j]<=2: TypeError: unsupported operand type(s) for -: 'list' and 'int'

错误:文件“n1.py”,第22行,而j中的所有内容都不是整数。在第3行你有
n=[]
(这是一个列表),然后在第21行你有
n-1

不能在int列表之间使用减法

这导致:

TypeError: unsupported operand type(s) for -: 'list' and 'int'

可能您想访问列表中的最后一项

n[-1]#确保至少有一个项,否则它会抛出索引器
或者,您可能希望获取列表的最后一个索引

len(n)-1

一切都不是整数。在第3行你有
n=[]
(这是一个列表),然后在第21行你有
n-1

不能在int列表之间使用减法

这导致:

TypeError: unsupported operand type(s) for -: 'list' and 'int'

可能您想访问列表中的最后一项

n[-1]#确保至少有一个项,否则它会抛出索引器
或者,您可能希望获取列表的最后一个索引

len(n)-1

请不要使用屏幕截图共享您的代码,而是直接在您的问题中复制。请不要使用屏幕截图共享您的代码,而是直接在您的问题中复制。