pesquisa

URI PROBLEMA 1154 - Idades SOLUÇÃO EM PYTHON

URI Online Judge | 1154

Idades

Adaptado por Neilor Tonin, URI Brasil
Timelimit: 1
Faça um algoritmo para ler um número indeterminado de dados, contendo cada um, a idade de um indivíduo. O último dado, que não entrará nos cálculos, contém o valor de idade negativa. Calcular e imprimir a idade média deste grupo de indivíduos.

Entrada

A entrada contém um número indeterminado de inteiros. A entrada será encerrada quando um valor negativo for lido.

Saída

A saída contém um valor correspondente à média de idade dos indivíduos.
A média deve ser impressa com dois dígitos após o ponto decimal.



URI Online Judge | 1154

Ages

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Write an algorithm to read an undeterminated number of data, each containing an individual's age. The final data, which will not enter in the calculations, contains the value of a negative age. Calculate and print the average age of this group of individuals.

Input

The input contains an undetermined number of integers. The input will be stop when a negative value is read.

Output

The output contains a value corresponding to the average age of individuals.
The average should be printed with two digits after the decimal point.









x = 100
soma = 0
i = 0
while x >= 0:
    x = int(input())
    if x >= 0:
        i = i + 1
        soma = soma + x
media = soma / i
print('{:.2f}'.format(media))    

Postar um comentário

0 Comentários