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()
Asked
Active
Viewed 795 times
0

mozway
- 194,879
- 13
- 39
- 75

Rohanshaj KR
- 1
- 1
-
1can you provide a sample of input/output? – mozway Feb 04 '22 at 10:59
1 Answers
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