|
| 1 | +import random |
| 2 | +from enum import Enum |
| 3 | + |
| 4 | +events = [] |
| 5 | + |
| 6 | + |
| 7 | +class Country(Enum): |
| 8 | + SPAIN = "SP" |
| 9 | + FRANCE = "FR" |
| 10 | + GERMANY = "GER" |
| 11 | + ENGLAND = "EN" |
| 12 | + ITALY = "IT" |
| 13 | + |
| 14 | + |
| 15 | +class Participant: |
| 16 | + name: str |
| 17 | + country: Country |
| 18 | + |
| 19 | + def __init__(self, name, country): |
| 20 | + self.name = name |
| 21 | + self.country = country |
| 22 | + |
| 23 | + |
| 24 | +class Event: |
| 25 | + name: str |
| 26 | + participants: list |
| 27 | + gold: Participant |
| 28 | + silver: Participant |
| 29 | + bronze: Participant |
| 30 | + |
| 31 | + def __init__(self, name): |
| 32 | + self.name = name |
| 33 | + self.participants = [] |
| 34 | + self.gold = None |
| 35 | + self.silver = None |
| 36 | + self.bronze = None |
| 37 | + |
| 38 | + def simulate(self): |
| 39 | + random.shuffle(self.participants) |
| 40 | + if len(self.participants) >= 3: |
| 41 | + self.gold = self.participants[0] |
| 42 | + self.silver = self.participants[1] |
| 43 | + self.bronze = self.participants[2] |
| 44 | + else: |
| 45 | + print("El número de participantes no es suficiente") |
| 46 | + |
| 47 | + |
| 48 | +def print_winners(event: Event): |
| 49 | + print(f"\n| {event.name} |") |
| 50 | + try: |
| 51 | + print(f"*** Gold: {event.gold.name} - {event.gold.country}") |
| 52 | + print(f"** Silver: {event.silver.name} - {event.silver.country}") |
| 53 | + print(f"* Bronze: {event.bronze.name} - {event.bronze.country}") |
| 54 | + except Exception as e: |
| 55 | + print(e) |
| 56 | + print("No hay resultados") |
| 57 | + |
| 58 | + |
| 59 | +def country_ranking(): |
| 60 | + countries = {} |
| 61 | + |
| 62 | + for country in Country: |
| 63 | + countries[country.name] = 0 |
| 64 | + |
| 65 | + for event in events: |
| 66 | + try: |
| 67 | + for medal in [event.gold, event.silver, event.bronze]: |
| 68 | + if medal: |
| 69 | + match medal.country: |
| 70 | + case 'IT': |
| 71 | + countries['ITALY'] += 1 |
| 72 | + case 'SP': |
| 73 | + countries['SPAIN'] += 1 |
| 74 | + case 'FR': |
| 75 | + countries['FRANCE'] += 1 |
| 76 | + case 'EN': |
| 77 | + countries['ENGLAND'] += 1 |
| 78 | + case 'GER': |
| 79 | + countries['GERMANY'] += 1 |
| 80 | + except Exception as e: |
| 81 | + print("⚠️ No se han realizado pruebas aún\n") |
| 82 | + |
| 83 | + for country, points in countries.items(): |
| 84 | + print(f"{country}: {points} points") |
| 85 | + |
| 86 | + |
| 87 | +def event_registration(): |
| 88 | + name = input("\nNombre del evento: ") |
| 89 | + new_event = Event(name=name) |
| 90 | + events.append(new_event) |
| 91 | + |
| 92 | + |
| 93 | +def paticipant_registration(): |
| 94 | + name = input("\nNombre del participante: ") |
| 95 | + country = input("País del participante (SP, FR, GER, EN, IT): ") |
| 96 | + print("Prueba en la que participa: ") |
| 97 | + |
| 98 | + for event in events: |
| 99 | + print(f"- {event.name}") |
| 100 | + |
| 101 | + selected_event = input("> ") |
| 102 | + |
| 103 | + new_participant = Participant(name, country) |
| 104 | + |
| 105 | + if country == "SP" or country == "FR" or country == "GER" or country == "EN" or country == "IT": |
| 106 | + |
| 107 | + found = False |
| 108 | + |
| 109 | + for event in events: |
| 110 | + if event.name == selected_event: |
| 111 | + event.participants.append(new_participant) |
| 112 | + found = True |
| 113 | + break |
| 114 | + |
| 115 | + if not found: |
| 116 | + print("Prueba no encontrada") |
| 117 | + else: |
| 118 | + print("Participante añadido correctamente") |
| 119 | + else: |
| 120 | + print("País erróneo") |
| 121 | + |
| 122 | + |
| 123 | +def make_report(): |
| 124 | + print("\n---------------") |
| 125 | + print("| Winners |") |
| 126 | + print("---------------") |
| 127 | + |
| 128 | + for event in events: |
| 129 | + print_winners(event) |
| 130 | + |
| 131 | + print("\n---------------------") |
| 132 | + print("| Country ranking |") |
| 133 | + print(" ---------------------") |
| 134 | + |
| 135 | + country_ranking() |
| 136 | + |
| 137 | + |
| 138 | +def main(): |
| 139 | + quit = False |
| 140 | + |
| 141 | + while not quit: |
| 142 | + print("\nSelecciona una opción:") |
| 143 | + print("1. Registro de eventos\n" |
| 144 | + "2. Registro de participantes\n" |
| 145 | + "3. Simulación de eventos\n" |
| 146 | + "4. Creación de informes\n" |
| 147 | + "5. Salir del programa") |
| 148 | + |
| 149 | + option = input("> ") |
| 150 | + |
| 151 | + match option: |
| 152 | + case "1": |
| 153 | + event_registration() |
| 154 | + case "2": |
| 155 | + paticipant_registration() |
| 156 | + case "3": |
| 157 | + for event in events: |
| 158 | + event.simulate() |
| 159 | + print("Simulación completada") |
| 160 | + case "4": |
| 161 | + make_report() |
| 162 | + case "5": |
| 163 | + quit = True |
| 164 | + case _: |
| 165 | + print("Opción no válida") |
| 166 | + |
| 167 | + |
| 168 | +if __name__ == '__main__': |
| 169 | + main() |
0 commit comments