dictionary_scrabble~20171216-073848.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Copyright (C) 2017 Constant, Algolit
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details: <http://www.gnu.org/licenses/>.
  12. '''
  13. Input texts are checked against a dictionary that assigns weights to different vowels.
  14. The script gives a score for a specific sentence.
  15. '''
  16. # create a dictionary
  17. scrabble = {'a': 3, 'e': 1, 'i': 2, 'o': 4, 'u':4, 'y': 6}
  18. # set weight to 0
  19. weights = 0
  20. # find a sentence / string
  21. sentence = "La vie est un mystère qu'il faut vivre, et non un problème à résoudre."
  22. # spllit sentence in list of words
  23. words = sentence.split()
  24. # for each word
  25. for word in words:
  26. # iterate over letters of word
  27. for letter in word:
  28. # check if letter is in dictionary
  29. if letter in scrabble:
  30. # if yes, get weight of the letter
  31. weight = scrabble[letter]
  32. # add letter weight to general weight
  33. weights += weight
  34. # print general weight
  35. print("Le poids de ma phrase est:", weights)