With creating a program that reads 10 numbers and writes the lowest and highest read value (Python)?

Asked

Viewed 178 times

-4

I’m having a little trouble with this exercise. Here is my code:

python
num = float(input('Digite o 1 numero: '))

guarda_maior = num
guarda_menor = num

for n in range(1, 10):

    num = float(input(f'Digite o valor de {n}: '))

    if num > guarda_maior:

        num = guarda_maior

    elif num < guarda_menor:

        num = guarda_menor

print(f'{guarda_maior}, {guarda_menor}')

If anyone can help me. Grateful.

1 answer

-2


The problem was that the num was getting the var instead of the var getting the num

if num > guarda_maior:

        guarda_maior = num #troquei a ordem, agora guarda_maior recebera num ao inves de num receber guarda_maior

    elif num < guarda_menor:

        guarda_menor = num #troquei a ordem, agora guarda_menor recebera num ao inves de num receber guarda_menor

print(f'{guarda_maior}, {guarda_menor}')

That way I believe it will be solved.

Browser other questions tagged

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