Created
March 22, 2020 14:28
-
-
Save lunhg/0968846d580df672087566c9b22bab76 to your computer and use it in GitHub Desktop.
Script para Exercício 10 da atividade da semana 3 - Univesp
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
#!/usr/bin/python | |
from optparse import OptionParser | |
# PROGRAMA PRINCIPAL | |
PROG = "fluxograma-10" | |
VERSION = "0.0.1" | |
description = "Calcula o fluxograma do exercício 10 da atividade da semana 3" | |
parser = OptionParser(usage='usage: %prog [OPTIONS, [ARGS]]', | |
version='%s %s' % (PROG, VERSION), | |
description=description) | |
# Opcoes do programa | |
parser.add_option("-N", "--numero", action=None, help="Número. Ex.: --numero 4") | |
parser.add_option("-X", "--incognita", action=None, help="Incógnita. Ex.: --incognita 3") | |
parser.add_option("-V", "--verbose", action=None, help="Apresenta mensagens do cálculo (valor-padrão igual a 0; até 3). Ex.: --verbose 2") | |
# Capturar os argumentos passados pelo parser | |
(options, args) = parser.parse_args() | |
# mudar tipos | |
def process(N, X, verbose=0): | |
a = 2 | |
resposta = X | |
if(verbose >= 1): | |
print("level 1") | |
print("=== A: %s" % a) | |
print("=== X: %s" % X) | |
print("=== N: %s" % N) | |
while(a <= N): | |
if(verbose >= 1): | |
print("level 2") | |
print("=== A: %s" % a) | |
print("=== X: %s" % X) | |
print("=== N: %s" % N) | |
exp = X | |
b = 1 | |
while(b < a): | |
if(verbose >= 2): | |
print("level 3") | |
print("=== exp: %s" % exp) | |
print("=== b: %s" % b) | |
print("=== a: %s" % a) | |
exp *= X | |
b += 1 | |
if(b >= a): | |
resposta += exp | |
a += 2 | |
if(verbose >= 3): | |
print("level 4") | |
print("=== resposta: %s" % resposta) | |
print("=== a: %s" % a) | |
break | |
if(a > N): | |
if(verbose >= 1): | |
print("=== breaking") | |
break | |
return resposta | |
r = process(float(options.numero), float(options.incognita), int(options.verbose)) | |
print("Resposta: %s" % r) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment