Skip to content

Instantly share code, notes, and snippets.

@HectorSaldes
Last active October 12, 2021 02:33
Show Gist options
  • Save HectorSaldes/72e1cfdc94e1f414cfdb5cc70006ffff to your computer and use it in GitHub Desktop.
Save HectorSaldes/72e1cfdc94e1f414cfdb5cc70006ffff to your computer and use it in GitHub Desktop.
Trabajo sobre manipulación de archivos en la materia del profesor Ignacio Sánchez Moreno
"""
? Saldaña Espinoza Hector
* Seguridad informática
! 7B
"""
fileName = input('¿Nombre del archivo? ó (q/Q/salir/exit) Para salir: ')
fileName = fileName.lower()
if (fileName == 'q' or fileName == 'salir' or fileName == 'exit'):
print('Programa finalizado correctamente :)')
else:
file = open(f'{fileName}.txt', 'at')
while True:
text = input('Escriba algo ó (q/Q/salir/exit) Para salir: ')
text = text.lower()
if(text == 'q' or text == 'salir' or text == 'exit'):
print('Texto guardado correctamente :)')
break
else:
file.write(f"{text}\n")
file.close()
file = open(f'{fileName}.txt', 'r')
lines = file.readlines()
print(f'\nMostrando lineas escritas en el archivo {fileName}.txt: ')
for (i, line) in enumerate(lines):
i += 1
line = line[:-1]
print(f'{i}', end='. ')
if(i % 2 == 0):
print(line.lower())
else:
print(line.upper())
file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment