I don't know why am I doing wrong but it happens this weird error.
This is my code:
import os
from constants import BCOLORS
def clean_screen():
'''Clean the screen of the console'''
clear = lambda:os.system('clear')
clear()
def exit():
print(BCOLORS.OKBLUE + "See you later, alligator!!!" + BCOLORS.ENDC)
def doReportPreGame():
print("Informe pre partido")
def doReportPostGame():
print("Informe post partido")
def doReportMonthly():
print("Informe mensual")
def mainMenu():
clean_screen()
print("SELECCIONA EL TIPO DE INFORME")
print("=============================")
print("\t1. Informe Pre-Partido")
print("\t2. Informe post-partido")
print("\t3. Informe mensual")
print("\t0. Salir\n")
option = None
while option not in [1, 2, 3, 0]:
option = int(input("Opción: "))
switch(option)
def main():
mainMenu()
def switch(case):
sw = {
1: doReportPreGame(),
2: doReportPostGame(),
3: doReportMonthly()
}
return sw.get(case, exit())
main()
I have created a menu and to select an option I have developed a "switch", so, to decide which option to access I do it with a dictionary. If I entry a 0 I should to receive only this message: See you later, alligator!!!
But, I've got all these others:
/home/josecarlos/Workspace/python/reports/venv/python/bin/python /home/josecarlos/Workspace/python/reports/main.py
SELECCIONA EL TIPO DE INFORME
=============================
1. Informe Pre-Partido
2. Informe post-partido
3. Informe mensual
0. Salir
Opción: 0
Informe pre partido
Informe post partido
Informe mensual
See you later, alligator!!!
Process finished with exit code 0
If a select another option, I'm still getting the same result and not only the option selected.
/home/josecarlos/Workspace/python/reports/venv/python/bin/python /home/josecarlos/Workspace/python/reports/main.py
SELECCIONA EL TIPO DE INFORME
=============================
1. Informe Pre-Partido
2. Informe post-partido
3. Informe mensual
0. Salir
Opción: 1
Informe pre partido
Informe post partido
Informe mensual
See you later, alligator!!!
Process finished with exit code 0
What am I doing wrong? Why it happend this?