I'm still struggling with my work on text correction. It turns out that I have to store the output of my code in different text files that I also have to create.
my code is this:
cadena = "Bienvenido/a"
print(cadena.center(50, "="))
entrada = input('Introduzca aquí el nombre completo del texto a analizar en formato << .txt >>: ')
while entrada == '':
print('Ha habido un error al encontrar su fichero, por favor, inténtelo de nuevo')
entrada = input('Introduzca aquí el nombre completo del texto a analizar: ')
archivo = open(entrada, 'r')
texto = archivo.read()
def contar_palabras(texto):
count = 0
cc = ' '
for c in texto:
if c == ' ' and cc != ' ':
count += 1
cc = c
if c != ' ':
count += 1
return count
def contar_vocales(texto):
count = 0
for c in texto:
if c in "aeiouAEIOU":
count = count + 1
return count
def contar_consonantes(texto):
count = 0
for c in texto:
if c in "bcdfghjklmnñpqrstvwxyzBCDFGHJKLMNÑPQRSTVWXYZ":
count = count + 1
return count
def contar_mayusculas(texto):
count = 0
for c in texto:
if c in "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
count = count + 1
return count
def contar_minusculas(texto):
count = 0
for c in texto:
if c in "abcdefghijklmnopqrstuvwxyz":
count = count + 1
return count
def contar_numeros(texto):
count = 0
for c in texto:
if c in "0123456789":
count = count+ 1
return count
def contar_diferentes(texto):
count = 0
for c in texto:
if c in "!#$%&\'()*+,-./:;<=>?@[\]^_'{|}~\t\s\x0b\x0c":
count = count + 1
return count
def contar_parrafos(texto): #aqui tengo que afinar mas, estoy en ello
count = 0
letter = ''
for c in texto:
if c in "\n\r":
count = count + 1
return count
THE DEPARTURE OF THIS CODE I HAVE TO SAVE IN A FILE .TXT
THIS FOLLOWING VARIABLE 'CORRECTIONS' WOULD HAVE TO RECORD ME THE RESULT IN A DOC.TXT
def correcciones(libro):
modif = []
for c in texto:
tabs = 0
while c.startswith(" "):
tabs+=1
c = c[4:]
c = "\t"*tabs + c
c = re.sub(r"(\S) {2,}", r" ", c)
c = re.sub(r"([:;.,]+)(\S)", r" ", c)
modif.append(c)
return modif
A thousand thanks !!!!!