'<'在'NoneType'和'NoneType'实例之间不支持,在python中出现错误。

问题描述 投票:-4回答:1
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])

在这个程序中,我们的假设是,我们给一个整数,显示学生的数量,然后我们给ID一个学生的AVG,最后我们显示第二个AVG的伟大。

python
1个回答
0
投票

如果你把一个元素追加到一个列表中应该这样做。

b.append(int(input('student ID')))
c.append(int(input('AVG? ')))

这将会得到一个包含整数值的列表,而不是... NoneType.

对于最后两个for循环,你应该考虑使用 range(n-1) 而不是 range(n),因为你每次循环迭代都要检查是否有 i+1 拔苗助长

IndexError: list index out of range

在最后一次迭代中,因为 n+1 > n.

© www.soinside.com 2019 - 2024. All rights reserved.