Stay in Loop until the entered value is negative

Asked

Viewed 312 times

-1

Write a program that reads multiple integers until a negative number is typed. The program has to return the smallest and largest number read.

I tried to do, but when it comes to show the smallest number read is always showing the 0.

maior = menor = valor = i = 0
print('Digite números inteiros! Um número menor que zero para o programa!')
while valor >= 0:
    valor = int(input(f'Digite o {i + 1}° valor: '))
    if valor > maior:
        maior = valor
    if (valor < menor) and (valor >= 0):
        menor = valor
    i += 1
print(maior)
print(menor)
  • If the value has to be >= 0 and you set it to zero initial value then no value reported will be less than this initial value. Try to put as many as possible to be represented on this type of data.

1 answer

-2


Boot with a large number the smallest, 0 will always be the smallest in the natural

Browser other questions tagged

You are not signed in. Login or sign up in order to post.