Skip to content

Instantly share code, notes, and snippets.

@MM-coder
Created November 2, 2019 10:56
Show Gist options
  • Save MM-coder/ce71a66566f16f2aa5e90f712519e49a to your computer and use it in GitHub Desktop.
Save MM-coder/ce71a66566f16f2aa5e90f712519e49a to your computer and use it in GitHub Desktop.
Get the max of a list without using the inbuilt max() function
a = [5,9,19,0,3,-45,7,3,-20]
b = [-19,2,3,-8,3.5,18.9, 24]
def maximo(lista: list):
maximo = lista[0]
for i in lista:
if maximo < i:
maximo = i
return maximo
print("O maximo da lista a e: " + str(maximo(a)))
print("O maximo da lista b e: " + str(maximo(b)))
if maximo(a) > maximo(b):
print("O maximo da lista a e maior do que o da lista b")
elif maximo(a) < maximo(b):
print("O maximo da lista b e maior do que o da lista a")
else:
print("Os maximos das listas a e b sao iguais")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment