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])
in this program, the purpose is that we give an integer that shows the number of students then we give ID an AVG of students and at last we show the second AVG in Greatness
If you append an element to a list you should do this in this way:
b.append(int(input('student ID')))
c.append(int(input('AVG? ')))
This will get you a list with integer values instead of NoneType
.
For the last two for loops you should consider using range(n-1)
instead of range(n)
, since you are checking every loop iteration for i+1
which will always raise IndexError: list index out of range
at the last iteration because n+1 > n
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.