forked from mouredev/roadmap-retos-programacion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mouredev.py
41 lines (27 loc) · 882 Bytes
/
mouredev.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import os
import csv
import random
def read_csv_data() -> list:
file_dir = os.path.dirname(os.path.abspath(__file__))
csv_file = f"{file_dir}/subs.csv"
data = []
with open(csv_file, mode="r") as file:
reader = csv.DictReader(file)
for row in reader:
if row["status"] == "activo":
data.append(row)
return data
def select_winners(data: list) -> list:
if len(data) < 3:
raise ValueError("El número de elementos debe ser mínimo 3.")
return random.sample(data, 3)
def display_winners(winners):
prizes = ["Suscripción", "Descuento", "Libro"]
for winner, prize in zip(winners, prizes):
print(f"{prize}: {winner["email"]} (ID: {winner["id"]})")
try:
data = read_csv_data()
winners = select_winners(data)
display_winners(winners)
except Exception as e:
print(e)