Exercise - Taking time in seconds and returning to the average and lower values to the average

Asked

Viewed 37 times

-1

I have an exercise where it requires that a program be created that receives racing time as input and calculates the arithmetic average of the times spent to travel a daily race course. At the end the program should display all times that were below the media in the same order that was received in the entry.

INPUT: Several integer values, one per line that represses the times spent on each race (in seconds), the entry and finalized with the insertion of a negative value that should not be accounted for.

EXIT In the first line the word "MEDIA: " shall be printed followed by the real value with two decimal places indicating the average of the times received. In the following lines the times that were below the media being printed one per line.

EXAMPLES

EXEMPLO

What I’ve achieved so far is this::

lista = []
segundos = int(input())

while segundos >= 0:
        lista.append(segundos)
        segundos = int(input())

media = sum(lista) / len(lista)
print(f'MEDIA: {media:.2f}')

However I was not able to make impression of values less than the average.

1 answer

0


You just need to go through the list by making one if. If it is less than the average printa, otherwise.

Something more or less like this:

lista = []
segundos = int(input())

while segundos >= 0:
        lista.append(segundos)
        segundos = int(input())

media = sum(lista) / len(lista)
print(f'MEDIA: {media:.2f}')
for x in lista:
    if x < media:
       print(x)
  • Evilmaax, it worked, I was confusing thinking that I needed to put inside the White.

  • Oops, good @Mardoquelgadi. Then give the upvote and mark the answer as accepted by clicking on "Check". So you help me, help yourself (earn points) and help anyone else get here needing that answer. Hugs

Browser other questions tagged

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