avkLab

Statistiques texte

Jun 11th, 2022
1,078
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. #----------------------------------------------------------------------------
  4. # Created by  : Alain Van Kerckhoven
  5. # Created Date: 13 juillet 2016
  6. # Licence     : GPL
  7. # Version     : 1.0
  8. # ---------------------------------------------------------------------------
  9. """
  10. Compte les lettres, les voyelles et les mots d'une phrase.
  11. """
  12. # ---------------------------------------------------------------------------
  13.  
  14.  
  15. def vowel_count(str):
  16.     count = 0
  17.     vowel = set("aàâäeéèêëioöuüùAEIOU")
  18.    
  19.     for alphabet in str:
  20.         if alphabet in vowel:
  21.             count = count + 1
  22.     return (count)
  23.  
  24.  
  25. def words_count(str):
  26.     prec = " "
  27.     nb_mots = 0
  28.     for char in str:
  29.         nb_mots = nb_mots + int(prec == " " and char != " ")
  30.         prec = char
  31.     return (nb_mots)
  32.  
  33.  
  34. phrase = input("Entrez un texte à analyser : ")
  35.  
  36. nbcar = len(phrase)
  37. nbvowel = vowel_count(phrase)
  38. nbwords = words_count(phrase)
  39.  
  40. print("Nb de caractères :", nbcar)
  41. print("Nb de voyelles :", nbvowel)
  42. print("Nb de mots :", nbwords)
  43.  
Advertisement
Add Comment
Please, Sign In to add comment