Created
October 5, 2018 19:06
-
-
Save tiagox/8d4540d3e4985b9dcab43ad0c789485b to your computer and use it in GitHub Desktop.
This file contains 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
import csv | |
import pickle | |
def calcular_cuotas(archivo_entrada, archivo_salida, valor_cuota): | |
''' Ejercicio 1 ''' | |
with open(archivo_entrada, 'r') as entrada, open(archivo_salida, 'w') as salida: | |
escritor = csv.writer(salida, quoting=csv.QUOTE_NONNUMERIC) | |
escritor.writerow(["Nombre", "Nro de Socio", "Categoría", | |
"Cantidad de cuotas", "Importe"]) | |
lector = csv.reader(entrada) | |
next(lector) | |
for nombre, nro_socio, categoria, cuotas_pendientes in lector: | |
cantidad_cuotas = int(cuotas_pendientes) + 1 | |
try: | |
fila = [nombre, nro_socio, categoria, cantidad_cuotas, | |
cantidad_cuotas * valor_cuota[categoria]] | |
except KeyError: | |
print('"%s", "%s", "%s" categoría inexistente' % | |
(nombre, nro_socio, categoria)) | |
else: | |
escritor.writerow(fila) | |
def faltan_datos(socios, deportes): | |
''' Ejercicio 2.i ''' | |
faltantes = {} | |
for deporte in deportes: | |
for socio in deportes[deporte]: | |
if socio not in socios: | |
if socio in faltantes: | |
faltantes[socio].append(deporte) | |
else: | |
faltantes[socio] = [deporte] | |
return faltantes | |
def guardar_datos_faltan_en_disco(faltan_datos, archivo): | |
''' Ejercicio 2.ii ''' | |
with open(archivo, 'wb') as salida: | |
pickle.dump(faltan_datos, salida) | |
def recuperar_datos_faltan_en_disco(archivo): | |
''' Ejercicio 2.iii ''' | |
with open(archivo, 'rb') as entrada: | |
print(pickle.load(entrada)) | |
if __name__ == '__main__': | |
valor_cuota = { | |
"Cadete": 100, | |
"Mayor": 200, | |
"Vitalicio": 0 | |
} | |
calcular_cuotas("entrada.csv", "salida.csv", valor_cuota) | |
socios = { | |
100: ('Ana', 'Cadete'), | |
101: ('Juan', 'Mayor'), | |
102: ('Juana', 'Cadete'), | |
103: ('Lucía', 'Mayor') | |
} | |
deportes = { | |
'Tenis': [99, 100, 101, 102, 105], | |
'Natación': [99, 100, 101, 105], | |
'Voley': [101, 102, 106] | |
} | |
socios_faltan = faltan_datos(socios, deportes) | |
guardar_datos_faltan_en_disco(socios_faltan, 'socios_faltan.pickle') | |
recuperar_datos_faltan_en_disco('socios_faltan.pickle') |
This file contains 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
Nombre | Nro de Socio | Categoría | Meses adeudados | |
---|---|---|---|---|
Ana | 100 | Cadete | 3 | |
Juan | 101 | Mayor | 0 | |
Luis | 104 | Moroso | 5 | |
Juana | 102 | Vitalicio | 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment