-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathej_archivos.py
More file actions
24 lines (22 loc) · 864 Bytes
/
ej_archivos.py
File metadata and controls
24 lines (22 loc) · 864 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
nombre_archivo=input("Ingrese nombre del archivo:->>")
archivo=open(nombre_archivo,"r")
texto=archivo.read()
archivo.close()
lineas=texto.splitlines()
terminos=texto.split(":")
diccionario={}
for linea in lineas:
termino=linea.split(":")
diccionario[termino[0]]=termino[1]
buscar=input("Indique el termino a buscar en el diccionario:->>")
encontrado=diccionario.get(buscar)
if encontrado:
print(buscar+":"+" "+encontrado)
else:
print("El termino buscado no esta en el glosario")
ingresar_termino=input("Desea ingresar el termino (n/s):->>")
if ingresar_termino == "s":
archivo=open(nombre_archivo,"a")
nuevo_termino=input("Ingrese la description del nuevo termino:->>")
archivo.write(buscar+":"+nuevo_termino+"\n")#(\n) segun donde se coloque, tanto de principio (agregar) o final (comezar)
archivo.close()