[英]TypeError: '>' not supported between instances of 'int' and 'NoneType' in Python
[英]'<' not supported between instances of 'NoneType' and 'NoneType' error in python
b=[]
c=[]
n=int(input('number of students??'))
if n<2:
print('please enter a number larger than 1:')
for i in range(n):
b[i]=b.append(int(input('student ID')))
c[i]=c.append(int(input('AVG? ')))
for j in range(n):
for i in range(n):
if c[i] < c[i+1]:
t=c[i]
c[i]=c[i+1]
c[i+1]=t
t= b[i]
b[i] = b[i + 1]
b[i + 1] = t
print(c[1])
在这个程序中,目的是我们给出一个 integer 来显示学生的数量,然后我们给 ID 一个学生的 AVG,最后我们在 Greatness 中显示第二个 AVG
如果您将 append 元素添加到列表中,您应该这样做:
b.append(int(input('student ID')))
c.append(int(input('AVG? ')))
这将为您提供一个包含 integer 值而不是NoneType
的列表。
对于最后两个 for 循环,您应该考虑使用range(n-1)
而不是range(n)
,因为您正在检查i+1
的每个循环迭代,这将始终引发IndexError: list index out of range
在最后一次迭代,因为n+1 > n
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.