How to make python select the largest number in a set?

0

Good afternoon, I'm inputting numbers in python, but I do not know how to do it to aggregate them to a set and then have python decide which is the largest number in the list.

Thankful

    
asked by anonymous 18.04.2017 / 19:01

2 answers

1

Considering only integers (you can adapt to other types):

Version with for:

lista = []
qtn = input('informe a qt de numeros: ')

for n in range(0,int(qtn)): 
    lista.append(int(input('Digite o número: ')))

print ('Maior número da lista: ', max(lista))    

Version with while:

lista = []
while True:
    n = int(input('Digite o número (0 para encerrar): '))
    if n == 0:
        break
        lista.append(n)

print ('O maior número da lista é: ',max(lista))  

Version with for ...
Version with while ...

    
18.04.2017 / 19:23
0

I'm starting now in python, but I realized that the while loop would be correct if it were written like this:

lista = []
while True:
    n = int(input('Digite o número (0 para encerrar): '))
    lista.append(n)
    if n == 0:
        break


print ('O maior número da lista é: ',max(lista))*

Sorry if I mentioned anything wrong.

    
31.01.2018 / 15:51