uaveiro-leci/1ano/1semestre/fp/aula04/media.py

23 lines
546 B
Python
Raw Normal View History

2022-10-15 22:17:04 +00:00
# Pede ao utilizadores todas as parcelas e adiciona-as à lista 'values'
2022-10-14 22:03:25 +00:00
def GetValues():
2023-01-30 16:48:43 +00:00
count = 1
2022-10-18 17:18:56 +00:00
values = []
2022-10-14 22:03:25 +00:00
while True:
2023-01-30 16:48:43 +00:00
n = input('n{}: '.format(count))
if n == "":
break
2022-10-14 22:03:25 +00:00
values.append(float(n))
2023-01-30 16:48:43 +00:00
count += 1
2022-10-18 17:18:56 +00:00
return values
2022-10-14 22:03:25 +00:00
2022-10-15 22:17:04 +00:00
# Calcula a média dos valores da lista 'values'
2022-10-14 22:03:25 +00:00
def GetMedia(val):
2022-10-18 17:18:56 +00:00
return sum(val) / len(val)
2022-10-14 22:03:25 +00:00
2022-10-15 22:17:04 +00:00
# Função principal
2022-10-14 22:03:25 +00:00
def main():
2022-10-18 17:18:56 +00:00
values = GetValues()
2022-10-14 22:03:25 +00:00
print('Média dos valores introduzidos: ', GetMedia(values))
2022-10-18 17:18:56 +00:00
if __name__ == "__main__":
main()