xxMattewxx

Untitled

Apr 8th, 2021
387
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import sys
  2.  
  3. valores = []
  4.  
  5. #Função percorre todos os valores na array, e retorna a soma de todos os valores dentro
  6. def somarValores(arr):
  7.     soma = 0
  8.     for i in arr:
  9.         soma += i
  10.     return soma
  11.  
  12. #Este for permanece rodando enquanto existirem linhas para serem lidas no stdin, que é a entrada padrão
  13. for line in sys.stdin:
  14.     #Como stdin inclui quebra de linha, precisamos tirar a quebra de linha, e isso o rstrip faz.
  15.     line = line.rstrip()
  16.     if line == 'off':
  17.         break
  18.    
  19.     valores.append(int(line))
  20.     if len(valores) > 3:
  21.         valores.pop(0)
  22.  
  23.     media = somarValores(valores) / len(valores)
  24.     print(media)
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×