Skip to content

Instantly share code, notes, and snippets.

@echiesse
Last active March 17, 2018 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save echiesse/0ef41ba4d9708189fbfb6d3bb2567559 to your computer and use it in GitHub Desktop.
Save echiesse/0ef41ba4d9708189fbfb6d3bb2567559 to your computer and use it in GitHub Desktop.
Esqueleto de aplicação com suport a plugins
################################################################################
# mainMenu.py
mainMenu = [
'Areas',
'Volumes',
'Funcoes e, Equacoes (FE)',
'Potencias',
'Radicais',
'Trigonometria',
'Geometria',
'Logica Bivalente (LB)',
'Vetores',
'Estatistica',
'Sucessoes',
'Derivadas',
'Conjuntos e Probabilidades (CB)',
'Logaritimos',
'Limites Notaveis (LN)',
'Numeros Complexos (NC)',
]
################################################################################
# plugin_areas.py
from util import *
areasMenu = [
'Quadrado',
'Retangulo',
'Triangulo',
'Losangulo',
'Trapezio',
'Poligono Regular',
'Circulo',
'Cone',
'Esfera',
'Voltar',
]
def calcAreas():
print('''Qual area deseja calcular:''')
printMenu(areasMenu)
while True:
option = input('> ').upper()
if option == 'QUADRADO':
n1 = int(input('Digite a medida de um dos lados do quadrado: '))
r = print(f'A area do {option} é: {n1*n1}')
elif option == 'RETANGULO':
n1 = int(input('Digite o comprimento do retangulo:'))
n2 = int(input('Digite a largura do retangulo: '))
r = print(f'A area do {option} é: {n1}*{n2}={n1*n2}')
elif option == 'VOLTAR':
break
#elif option == 'TRIANGULO':
# n1 = int(
################################################################################
# util.py
#from importlib import import_module
def printMenu(menu):
for item in menu:
print(f' {item}')
#def getHandler(name):
# module = import_module(f"plugin_{name.lower()}")
# name = name.title()
# functionName = f"calc{name}"
# return getattr(module, functionName, None)
################################################################################
# main.py
from mainMenu import mainMenu
from util import *
from plugin_areas import *
version = 'Xavier'
def greeting():
print(f'Bem vindo(a) ao {version}. O que deseja calcular')
def getHandler(name):
name = name.title()
return globals().get(f"calc{name}")
def main():
greeting()
printMenu(mainMenu)
while True:
resposta = input('>>> ').upper()
handler = getHandler(resposta)
if handler != None :
handler()
else:
print('Comando não encontrado!!!')
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment