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

22 lines
522 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():
c = 1
2022-10-18 17:18:56 +00:00
values = []
2022-10-14 22:03:25 +00:00
while True:
n = input('n{}: '.format(c))
if n == "": break
values.append(float(n))
c += 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()