I wanted to try to optimize the code but my idea is not working.
I will receive a value from the user, this value will be a number, this number I will choose a function to be executed. So I created an object with those same numbers and the value the name of the function that should be called. I tried a few ways here but none worked, does anyone know how to do this? code right away
def funcaoSerExecutada():
modules = {
1: "funcao1()",
2: "funcao2",
3: "funcao3",
4: "funcao4",
5: "funcao5",
}
userValue = 0
# Texto que será exebido na tela
print("===============================")
print("Escolha o módulo")
print("===============================")
print("1 - Estrutura: modelo_cantacom_vitrine_destinos_mod019_V3")
print("2 - Estrutura: cantacom_n_mod072_aereas_100_V2;")
print("3 - Estrutura: canta_destinos_vitrine_novo_modelo_estrutura;")
print("4 - Estrutura: canta_mod050_estrutura; Obs: Valores apenas para Clube Smiles")
print("5 - CANTACOM_100MILHAS-SMILESANDMONEY-VERTICAL_V1")
print("===============================")
# Pedir para o usuário digitar um valor, verificar se é um número e se essa opção digitada existe
while (isinstance(userValue, str) or not userValue in modules):
try:
userValue = int(input("Digite um número: "))
if(not userValue in modules):
print("===============================")
print("Essa opção não existe! Escolha uma das opções acima!")
print("===============================")
except:
print("===============================")
print("Ops, digite um número!")
print("===============================")
def funcao1():
print("oi")
def runFunction():
modules[userValue]
runFunction()