What is the problem with this code?


#1


I wrote this code to get name, student number and score and then find maximum, report and remove, but I have a problem with remove that I cannot eradicate that. When I run , I get IndexError: list index out of range line on line 37, although I cannot find what it the problem.

c=0
x=[]
y=[]
z=[]
"""o=int(input("enter menu:"))"""
while True:
    print("o=1:::add  ","o=2:::max  ","o=3:::find  ","o=4:::remove  ","o=5:::report  ","o=6:::exit")
    o=int(input("enter menu:"))
    if o==1:
        x.append(input("enter name:"))
        z.append(int(input("enter #:")))
        y.append(int(input("enter score:")))
        c+=1
        
    elif o==2:
        i=1
        for i in range(len(x)):
            y[i]= y[i] if y[i]>y[i-1] else y[i-1]
            """i+=1"""
        f=y[i-1]
        print("max=",y[i-1])
        
        for i in range(len(x)):
            if f==y[i]:
                print("xii=",x[i],"xzz=",z[i])       

    elif o==3:
        n=int(input("enter number:"))
        for i in range(len(x)):
            if n==z[i]:
                print(x[i],y[i])
            else:
                print("not found")
    elif o==4:
        p=int(input("enter student number:"))
        for i in range(len(x)):
            if p==z[i]:
                x.pop(i)
                y.pop(i)
                z.pop(i)
    elif o==5:
         for i in range(len(x)):
             print("name:",x[i],"st number:",z[i],"score:",y[i])
    elif o==6:
        break


Replace this line with your code.


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.