سؤال في الباثيون

hasna khoualdi

New member
You are required to complete the function maximum(x). where "x" is a list of numbers, and contains more than 2 numbers. the function is expected to return the highest number in that list.
 

ahmed

Administrator
تفضل هذا الإجابة على سؤالك
Python:
x = [1, 2, 3, 4]


def maximum(x):

    return max(x) #Built in function


print(maximum(x))


#OR


x = [1, 2, 3, 4] #Change this as much as you want


def maximum(x):

    largest = x[0] #Starts at first index

    for i in x:

        if i > largest: #If greater change the largest value

            largest = i

    return largest #Returns the largest value


print(maximum(x))
 
أعلى