1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| #Importing packages
import pandas as pd
import matplotlib.pyplot as plt
#Input texte
print("Entrez votre texte : ")
texte_input = input()
#Alphabet
abc = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
#Fonction
def my_count(lettre):
'''Compte le nombre de lettre donné dans un texte spécifique'''
nombres_lettres = 0
for lettres in texte_input:
if lettres == lettre:
nombres_lettres += 1
return nombres_lettres
#Creat dictionnary containing lettre and how many times they appear
compteur_total = {}
for alphalettre in abc:
compteur_total[alphalettre] = my_count(alphalettre)
#Creating DatFrame from dictionnary
Tableau_Compteur_de_lettre = pd.DataFrame(compteur_total , index = ['Nbrlettre'])
print(Tableau_Compteur_de_lettre)
#Try to display an histogram showing how many times letter appear
plt.hist(...)
plt.show() |
Partager