0
a=int(input('Enter number of values:'))

l=[]

for i in range(0,a):
    b=input('*Enter the value:')
    l.append(b)

print(l)

def findmax():
    j=0
    for i in range(0,a):
        k=j+1
        if(l[j]>l[k]):
            print (l[j]," is the max value")
        else:
            j=j+1

l.findmax()
mozway
  • 194,879
  • 13
  • 39
  • 75

1 Answers1

0

findmax is not an attribute of a list, it is a function. You have to call the function by writing findmax(), however a good practice would be to define your function for any list and not just for your list l. The program also has issues when you do if(l[j]>l[k]): because you are out of range.

Here is a piece of code that works as intended I believe.

def findmax(myList):
    myMax = myList[0]
    for i in myList:
        if i > myMax:
            myMax = i
    return myMax        

l = [1,2,3,4]
print(findmax(l))

This is worth a read : Difference between methods and attributes in python

Thibaultofc
  • 29
  • 10