Spaces:
Sleeping
Sleeping
feat(es): add Spanish coding exercises (Tier 1-3)
Browse files
languages/es/exercises/tier2/transformador.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Tier 2 - Ejercicio 3: Transformador de Datos / Data Transformer
|
| 2 |
+
# Dificultad: 猸愨瓙 | Tiempo estimado: 25 min
|
| 3 |
+
# Ejecutar: legesher run languages/es/exercises/tier2/transformador.py --lang es
|
| 4 |
+
#
|
| 5 |
+
# Archivo de entrada requerido (estudiantes.json):
|
| 6 |
+
# [
|
| 7 |
+
# {"nombre": "Mar铆a Garc铆a", "nota": 9},
|
| 8 |
+
# {"nombre": "Carlos L贸pez", "nota": 7},
|
| 9 |
+
# {"nombre": "Ana Mart铆nez", "nota": 5},
|
| 10 |
+
# {"nombre": "Juan Rodr铆guez", "nota": 3}
|
| 11 |
+
# ]
|
| 12 |
+
#
|
| 13 |
+
# Escala de calificaciones: 9-10 Sobresaliente, 7-8 Notable, 5-6 Aprobado, 0-4 Suspenso
|
| 14 |
+
|
| 15 |
+
importar json
|
| 16 |
+
|
| 17 |
+
definir convertir_calificacion(nota):
|
| 18 |
+
"""Convierte nota num茅rica a calificaci贸n espa帽ola."""
|
| 19 |
+
si nota >= 9:
|
| 20 |
+
devolver "Sobresaliente"
|
| 21 |
+
si_no nota >= 7:
|
| 22 |
+
devolver "Notable"
|
| 23 |
+
si_no nota >= 5:
|
| 24 |
+
devolver "Aprobado"
|
| 25 |
+
sino:
|
| 26 |
+
devolver "Suspenso"
|
| 27 |
+
|
| 28 |
+
definir transformar_datos():
|
| 29 |
+
"""Lee estudiantes, convierte notas y guarda resultados."""
|
| 30 |
+
con abrir("estudiantes.json", "r", encoding="utf-8") como f:
|
| 31 |
+
estudiantes = json.load(f)
|
| 32 |
+
|
| 33 |
+
por estudiante en estudiantes:
|
| 34 |
+
estudiante["calificacion"] = convertir_calificacion(estudiante["nota"])
|
| 35 |
+
imprimir(f"Nombre: {estudiante['nombre']} | Nota: {estudiante['nota']} | Calificaci贸n: {estudiante['calificacion']}")
|
| 36 |
+
|
| 37 |
+
con abrir("resultados.json", "w", encoding="utf-8") como f:
|
| 38 |
+
json.dump(estudiantes, f, ensure_ascii=falso, indent=2)
|
| 39 |
+
imprimir("Resultados guardados en resultados.json")
|
| 40 |
+
|
| 41 |
+
si __name__ == "__main__":
|
| 42 |
+
transformar_datos()
|