forked from mouredev/retos-programacion-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
Retos/Reto #19 - ANÁLISIS DE TEXTO [Media]/python/ycanas.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import re | ||
|
||
def analyze_text(text): | ||
number_sentences = len(text.split(".")) - 1 | ||
|
||
search = r"[.,:;¿?¡!()]" | ||
text = re.sub(search, '', text).lower().split(" ") | ||
number_words = len(text) | ||
|
||
longest_word = max(text, key=len) | ||
length_words = [len(word) for word in text] | ||
mean_words = sum(length_words) / number_words | ||
|
||
output = ( | ||
f"Número total de palabras: {number_words}" | ||
f"\nLongitud media de las palbras: {mean_words:.1f}" | ||
f"\nNúmero de oraciones del texto: {number_sentences}" | ||
f"\nPalabra mas larga: {longest_word}" | ||
) | ||
|
||
return output | ||
|
||
|
||
text = ( | ||
"El término digital se deriva de la forma en que las computadoras realizan las operaciones contando dígitos. " | ||
"Durante muchos años, las aplicaciones de la electrónica digital se limitaron a los sistemas informáticos. " | ||
"Hoy día, la tecnología digital tiene aplicación en un amplio rango de áreas además de la informática. " | ||
"Aplicaciones como la televisión, los sistemas de comunicaciones, de radar, sistemas de navegación y guiado, " | ||
"sistemas militares, instrumentación médica, control de procesos industriales y electrónica de consumo, usan " | ||
"todos ellos técnicas digitales." | ||
) | ||
|
||
print(analyze_text(text)) |