script1.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. import random
  4. occurences = ["What are the demands","There are no demands","The demands","Impossible demands", "Impossible demand","We demand the impossible","Impossible to demand"]
  5. # read from file
  6. with open("occupy.txt", "r") as source:
  7. # for each line
  8. txt = source.readline()
  9. print(txt)
  10. new_txt = txt.replace(democracy, democracy_shuffled)
  11. print(new_txt)
  12. # clean returns
  13. #line = line.strip()
  14. #print(line)
  15. democracy = "democracy"
  16. democracy_majuscule = democracy.upper()
  17. print(democracy_majuscule)
  18. liste = list( democracy )
  19. random.shuffle( liste )
  20. democracy_shuffled = ''.join( liste )
  21. print(democracy_shuffled)
  22. #replace what are the demands
  23. sentence = occurences[0]
  24. print("sentence:", sentence)
  25. sentence.replace("What are the demands"," what are the demands ")
  26. print(sentence)
  27. #replace there are no demands
  28. sentence = occurences[1]
  29. sentence.replace("there are no demands","therearenodemands")
  30. print(sentence)
  31. #reverse order
  32. sentence = occurences[4,5,7]
  33. chaine = "impossible demands, impossible demand, impossible to demand"
  34. chaine = chaine [::-1]
  35. print(chaine)
  36. # passer en majuscule
  37. sentence = occurences[6]
  38. #sentence = sentence.upper()
  39. #print(sentence)
  40. # écrire la nouvelle liste comme chaîne de caractères dans un fichier texte
  41. #with open('export.txt', 'w') as f:
  42. #f.write(script1)