-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
21 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
Exercícios resolvidos/Moodle exercícios lista 4/Exercício 008.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,23 @@ | ||
# Crie uma função que receba uma quantidade x de números e adicione-os a uma lista, em seguida imprima a média | ||
# desses números caso o número adicionado seja a string 'fim'. | ||
|
||
def adicao_numeros_lista(): | ||
lista_numeros = [] | ||
while True: | ||
numero = input('Digite um número (fim p/ encerrar): ') | ||
if numero == 'fim': | ||
break | ||
else: | ||
lista_numeros.append(int(numero)) | ||
return media(lista_numeros) | ||
|
||
|
||
def media(lista): | ||
total = 0 | ||
for i in lista: | ||
total += i | ||
return total / (len(lista)) | ||
|
||
|
||
print('Bem vindo ao programa de cálculo da média!') | ||
print(f'\nA média é {adicao_numeros_lista():.2f}') |