-2
in this exercise you need to find the harmonic average but it is giving error (the -1 is to stop the x and the x has to be between 1 and 10 3 and the n is the number of notes.) when it tries to rotate, it appears 0. if you can help me, thank you
media = 0
n = int(input())
while not -1:
x = int(input())
if 1 <= x <= 10 ** 3:
media = (n / (1 / x))
print(f'{(media)}')
It seems to me that there is an indentation error in the if command. I don’t know what you want with
while not -1:
by description I believe that should bewhile n <> -1:
. Since you don’t have another reading of the variablen
if it is different from -1 then it will go into infinite loop. From what I understand of harmonic average you would have to readn
values make the cumulative of the inverses and at the end, after all the accumulation, divide n by this accumulated.– anonimo