test3~20171216-172410.py 934 B

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. #déclare la variable sentence comme une chaîne de caractères
  4. sentence = "Derniers jours avant noel. -50% sur tout le magasin. Consonnez SVP!"
  5. print("phrase de départ :",sentence)
  6. #converti sentence en liste appelée words
  7. words = sentence.split()
  8. #print(words)
  9. # define new word as list
  10. new_word = []
  11. #retirer les a, e, i, o, u et y de chaque mot
  12. for word in words:
  13. word=word.replace("a","")
  14. word=word.replace("e","")
  15. word=word.replace("é","")
  16. word=word.replace("i","")
  17. word=word.replace("o","")
  18. word=word.replace("u","")
  19. word=word.replace("y","")
  20. #print(word)
  21. # add word to new word list
  22. new_word.append(word)
  23. #recomposer la phrase sans les voyelles
  24. print("phrase sans les voyelles :", " ".join(new_word))
  25. with open("phrase.txt","w") as destination:
  26. destination.write("phrase sans les voyelles :")
  27. destination.write(" ".join(new_word))