Created
March 31, 2022 23:36
-
-
Save dasosjt/d3ee11a5f3698320607cdc18d632f590 to your computer and use it in GitHub Desktop.
ex3 variation for
This file contains hidden or 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
#Diego Javier Sosa Torres | |
#sos14735 | |
#ejercicio3 seccion1 | |
#logica principal del programa | |
def main() -> None: | |
persons_dict_list = [] | |
selected_option = None | |
while True: | |
try: | |
print("Menu\n 1. Insert person\n 2. Calculate statistics\n 3. Close") | |
selected_option = int(input("selected option: ")) | |
if selected_option == 1: | |
persons_dict_list = new_person(input("insert person: "), persons_dict_list) | |
if selected_option == 2: | |
persons_dict_list = calculate_statistics(persons_dict_list) | |
if selected_option == 3: | |
print("closing.. ") | |
break | |
except: | |
print("incorrect selected option") | |
break | |
#flujo de ingreso nueva persona a la lista | |
def new_person(person, persons_dict_list) -> list: | |
months_dict = { | |
'enero': 1, | |
'febrero': 2, | |
'marzo': 3, | |
'abril': 4, | |
'mayo': 5, | |
'junio': 6, | |
'julio': 7, | |
'agosto': 8, | |
'septiembre': 9, | |
'octubre': 10, | |
'noviembre': 11, | |
'diciembre': 12 | |
} | |
person_parts = person.split(',') if person and person != "" else [] | |
if len(person_parts) > 1 and person_parts[0] != "" and person_parts[1] != "": | |
date = person_parts[1] | |
date_split = date.split('-') | |
if '-' in date and len(date_split) == 3 and date_split[1] != "" and date_split[1] in months_dict and len(list(date_split[2])) == 4: | |
date_number = calculate_date_number( | |
int(date_split[0]), | |
int(months_dict[date_split[1]]), | |
date_split[2] | |
) | |
persons_dict_list.append({ 'person': person_parts[0], 'date_number': date_number }) | |
else: | |
print('bad format') | |
else: | |
print('bad format') | |
return persons_dict_list | |
#calcular la fecha resultante | |
def calculate_date_number(day, month, year): | |
list_date_digit = [] | |
for date_digit in year: | |
list_date_digit.append(int(date_digit)) | |
return day + month + sum(list_date_digit) | |
#flujo de impresion de estadisticas y ordernar la lista | |
def calculate_statistics(persons_dict_list): | |
persons_dict_list = sorted(persons_dict_list, key=lambda a: a['date_number'], reverse=False) | |
if len(persons_dict_list) > 0: | |
print("highest number: ", persons_dict_list[0]) | |
if len(persons_dict_list) > 1: | |
print("second highest number: ", persons_dict_list[1]) | |
if len(persons_dict_list) > 2: | |
print("third highest number: ", persons_dict_list[2]) | |
return persons_dict_list | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment