1
text file used: https://easyupload.io/j5agtq The method is part of a class called Arqtext
Objective: The method does not use input and returns, in a tuple object, (1) the average number of words per sentence in the file, (2) the number of words in the sentence with the most words and (3) the number of words in the sentence with the least words. You may consider the symbols that delimit a sentence to be '!?.'.
What I did:
def media(self):
import string
marcadores = ["?", ".", "!"]
cont = 0
total_pal = 0
num_frases = 0
qtdade_palavras = []
frase = ""
with open(arq) as f:
texto = f.read()
# print(texto)
for char in texto:
frase += char
if char in marcadores:
# print(frase)
# print(len(frase.split()))
for pal in frase.split():
for i in string.punctuation:
if i in pal:
pal = pal.replace(i, "")
pal = pal.lower()
cont += 1
# print(cont)
total_pal += cont
num_frases += 1
frase = ""
qtdade_palavras.append(cont)
cont = 0
continue
print(f"O numero médio de palavras por sentença é {total_pal / num_frases}")
print(f"O número de palavras na sentença com mais palavras é {max(qtdade_palavras)}")
print(f"O número de palavras na sentença com menos palavras é {min(qtdade_palavras)}")
Out of my job:
O numero médio de palavras por sentença é 25.488888888888887
O número de palavras na sentença com mais palavras é 124
O número de palavras na sentença com menos palavras é 2
I observed that actually the sentence with fewer words has only 1 word and not TWO:
`Prophet!
What am I missing?
full source code: https://www.pastiebin.com/5df6940dbc109
Unable to find any errors, I tried to reproduce the code and everything went well with the expected results, the problem may be in the text you are opening, if you can put all the file that is opened in
with open(arq) as f:
, other than that, only a few lines that could be removed that make no difference unless you do something in another part of the code– Guilherme França de Oliveira
@Guilherme França de Oliveira: I will edit and put the full code link
– Ed S
@Guilherme França de Oliveira full code: https://www.pastiebin.com/5df6940dbc109
– Ed S
I could make the file available
raven.txt
? that maybe the solution to the problem is in it, that the code itself is running well, playing it here using any file getting the correct output, there are some things that you have to fix in your code, however, I will post here when I have the complete solution– Guilherme França de Oliveira
@Guilherme França de Oliveira Is in the question: https://easyupload.io/j5agtq
– Ed S