[英]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.