You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

python-S02-E10.md 1.4 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. % Programmation avec Python (Épisode 10)
  2. % Dimitri Merejkowsky
  3. # Quiz
  4. #
  5. ```python
  6. print(0b110)
  7. ```
  8. \vfill
  9. 1. 3
  10. 2. 6
  11. #
  12. ```python
  13. print(0x1F)
  14. ```
  15. \vfill
  16. 1. 31
  17. 2. 12
  18. #
  19. ```python
  20. x = ord('c') - ord('a')
  21. print(x)
  22. ```
  23. \vfill
  24. 1. 2
  25. 2. 'b'
  26. #
  27. ```python
  28. n = ord('a')
  29. y = chr(n + 4)
  30. print(y)
  31. ```
  32. \vfill
  33. 1. 3
  34. 2. 'e'
  35. #
  36. ```python
  37. data = bytearray(b"bonjour")
  38. data[0] = 18
  39. print(data)
  40. ```
  41. \vfill
  42. 1. `bytearray(b'\x12onjour')`
  43. 2. `bytearray(b'18onjour')`
  44. #
  45. ```python
  46. message = "J'aime le café"
  47. print(message.encode())
  48. ```
  49. \vfill
  50. 1. b"J'aime le cafe"
  51. 2. b"J'aime le caf\\xc3\\xa9"
  52. #
  53. ```python
  54. message = "J'aime le caf\xc3\xa9"
  55. print(message.decode())
  56. ```
  57. \vfill
  58. 1. "J'aime le caf?"
  59. 2. "J'aime le café"
  60. #
  61. ```python
  62. # le fichier message.txt contient la ligne:
  63. "Salut ça va ?"
  64. f = open("message.txt", "r")
  65. contenu = f.read()
  66. print(contenu)
  67. f.close()
  68. ```
  69. \vfill
  70. 1. Salut ça va ?
  71. 2. *rien*
  72. \vfill
  73. #
  74. ```python
  75. # le fichier réponse.txt est vide
  76. f = open("réponse.txt", "w")
  77. f.write("Ça roule")
  78. f.close()
  79. ```
  80. \vfill
  81. Que contient le fichier `réponse.txt` ?
  82. 1. il est vide
  83. 2. "Ça roule"
  84. #
  85. ```python
  86. # le fichier poème.txt est vide
  87. f = open("poème.txt", "w")
  88. f.write("Un viel étang\n")
  89. f.write("Une grenouille qui plonge\n")
  90. f.write("Le bruit de l'eau")
  91. f.close()
  92. ```
  93. \vfill
  94. Que contient le fichier `poème.txt` ?
  95. 1. Un joli haïku
  96. 2. Une recette de cuisine