Last active
August 12, 2020 19:17
-
-
Save lunhg/42192af7d4d3436e5830287c004af8bb to your computer and use it in GitHub Desktop.
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
################################# | |
# Uso: | |
# $> python media_armortizada.py --help | |
# $> python media_armortizada.py --lista 1,2,3 --armortiza 4 | |
# $> python media_armortizada.py -l 1,2,3 -X 4 | |
################################# | |
from optparse import OptionParser | |
# PROGRAMA PRINCIPAL | |
PROG = "media-armortizada" | |
VERSION = "0.0.1" | |
description = "aplicação do algoritmo de média harmônica armortizada" | |
parser = OptionParser(usage='usage: %prog [OPTIONS, [ARGS]]', | |
version='%s %s' % (PROG, VERSION), | |
description=description) | |
parser.add_option("-l", "--lista", action=None, help="valores separados por virgula") | |
parser.add_option("-X", "--armortiza", action=None, help="Valor do coeficiente de armortização") | |
def SUM(lista, X): | |
S = 0 | |
for e in lista: | |
S = S + (1/(e+X)) | |
return S | |
def H(lista, X): | |
N = len(lista) | |
return (N/SUM(lista, X)) - X | |
(options, args) = parser.parse_args() | |
lista = [ float(e) for e in options.lista.split(",") ] | |
X = float(options.armortiza) | |
print(H(lista, X)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment