1
+ """
2
+ /*
3
+ * EJERCICIO:
4
+ * El nuevo año está a punto de comenzar...
5
+ * ¡Voy a ayudarte a planificar tus propósitos de nuevo año!
6
+ *
7
+ * Programa un gestor de objetivos con las siguientes características:
8
+ * - Permite añadir objetivos (máximo 10)
9
+ * - Calcular el plan detallado
10
+ * - Guardar la planificación
11
+ *
12
+ * Cada entrada de un objetivo está formado por (con un ejemplo):
13
+ * - Meta: Leer libros
14
+ * - Cantidad: 12
15
+ * - Unidades: libros
16
+ * - Plazo (en meses): 12 (máximo 12)
17
+ *
18
+ * El cálculo del plan detallado generará la siguiente salida:
19
+ * - Un apartado para cada mes
20
+ * - Un listado de objetivos calculados a cumplir en cada mes
21
+ * (ejemplo: si quiero leer 12 libros, dará como resultado
22
+ * uno al mes)
23
+ * - Cada objetivo debe poseer su nombre, la cantidad de
24
+ * unidades a completar en cada mes y su total. Por ejemplo:
25
+ *
26
+ * Enero:
27
+ * [ ] 1. Leer libros (1 libro/mes). Total: 12.
28
+ * [ ] 2. Estudiar Git (1 curso/mes). Total: 1.
29
+ * Febrero:
30
+ * [ ] 1. Leer libros (1 libro/mes). Total: 12.
31
+ * ...
32
+ * Diciembre:
33
+ * [ ] 1. Leer libros (1 libro/mes). Total: 12.
34
+ *
35
+ * - Si la duración es menor a un año, finalizará en el mes
36
+ * correspondiente.
37
+ *
38
+ * Por último, el cálculo detallado debe poder exportarse a .txt
39
+ * (No subir el fichero)
40
+ */
41
+ """
42
+ import os
43
+
44
+ MAX_OBJETIVOS : int = 10
45
+ OBJETIVOS : list = []
46
+ MESES_DEL_AÑO : list = [
47
+ 'Enero' , 'Febrero' , 'Marzo' , 'Abril' ,
48
+ 'Mayo' , 'Junio' , 'Julio' , 'Agosto' ,
49
+ 'Septiembre' , 'Octubre' , 'Noviembre' , 'Diciembre'
50
+ ]
51
+
52
+ def crear_objetivo ():
53
+ objetivo = {}
54
+ objetivo ['meta' ] = input ('Introduce la meta: ' )
55
+ objetivo ['cantidad' ] = int (input ('Introduce la cantidad: ' ))
56
+ objetivo ['unidades' ] = input ('Introduce las unidades: ' )
57
+ objetivo ['plazo' ] = int (input ('Introduce el plazo (en meses): ' ))
58
+ return objetivo
59
+
60
+ def objetivos_calculados (objetivo : dict ) -> list :
61
+ cantidad_total = objetivo ['cantidad' ]
62
+ plazo = objetivo ['plazo' ]
63
+
64
+ cantidad_mensual = cantidad_total // plazo
65
+ resto = cantidad_total % plazo
66
+
67
+ cantidades = [cantidad_mensual ] * plazo
68
+
69
+ for i in range (resto ):
70
+ cantidades [i ] += 1
71
+
72
+ return cantidades
73
+
74
+ def crear_txt (objetivos : list ):
75
+ with open ("objetivos_de_año_nuevo.txt" , "w" ) as fichero :
76
+ for objetivo in objetivos :
77
+ cantidades = objetivos_calculados (objetivo )
78
+ fichero .write (f"Meta: { objetivo ['meta' ]} \n " )
79
+ fichero .write (f"Cantidad total: { objetivo ['cantidad' ]} { objetivo ['unidades' ]} \n " )
80
+ fichero .write (f"Plazo: { objetivo ['plazo' ]} meses\n " )
81
+ fichero .write ("Distribucion mensual:\n " )
82
+ for i , cantidad in enumerate (cantidades ):
83
+ fichero .write (f"{ MESES_DEL_AÑO [i ]} : { cantidad } { objetivo ['unidades' ]} \n " )
84
+ fichero .write ("\n " )
85
+
86
+ def mostrar_objetivos ():
87
+ for mes in MESES_DEL_AÑO :
88
+ print (f"-----------{ mes } -----------" )
89
+ for objetivo in OBJETIVOS :
90
+ cantidades = objetivos_calculados (objetivo )
91
+ for i in range (objetivo ['plazo' ]):
92
+ if i < len (MESES_DEL_AÑO ):
93
+ if MESES_DEL_AÑO [i ] == mes :
94
+ print (f"[ ] { objetivo ['meta' ]} ({ cantidades [i ]} { objetivo ['unidades' ]} /mes). Total: { objetivo ['cantidad' ]} ." )
95
+
96
+ # Ejemplo de uso
97
+ while True :
98
+ opcion = input ("Elige una opción:\n 0. Mostrar objetivos\n 1. Crear objetivo\n 2. Mostrar objetivos por mes\n 3. Exportar a txt\n 4. Salir\n Introduce el número de la opción: " )
99
+
100
+ if opcion == '0' :
101
+ mostrar_objetivos ()
102
+
103
+ elif opcion == '1' :
104
+ if not len (OBJETIVOS ) >= MAX_OBJETIVOS :
105
+ OBJETIVOS .append (crear_objetivo ())
106
+ else :
107
+ print ("Has alcanzado el límite de objetivos." )
108
+
109
+ elif opcion == '2' :
110
+ for mes in MESES_DEL_AÑO :
111
+ print (f"-----------{ mes } -----------" )
112
+ for objetivo in OBJETIVOS :
113
+ cantidades = objetivos_calculados (objetivo )
114
+ for i in range (objetivo ['plazo' ]):
115
+ if i < len (MESES_DEL_AÑO ):
116
+ if MESES_DEL_AÑO [i ] == mes :
117
+ print (f"[ ] { objetivo ['meta' ]} ({ cantidades [i ]} { objetivo ['unidades' ]} /mes). Total: { objetivo ['cantidad' ]} ." )
118
+
119
+ elif opcion == '3' :
120
+ crear_txt (OBJETIVOS )
121
+
122
+ elif opcion == '4' :
123
+ break
0 commit comments