Embercode
✕
LoopsQuick quiz

Float drift and output in Python

6 questions. Covers Buffered output in Python.

Questions 1 to 5 of 6

  1. 1. What does this code print? ``python count = 0 y = 0.0 while y <= 0.6: count += 1 y += 0.1 print(count) ``
  2. 2. The output goes to a file. In what order do the three lines appear in the file? ``python import io import sys out = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8") out.write("buffered line A\n") print("direct line B") out.write("buffered line C\n") out.flush() ``
  3. 3. True or false: adding 0.1 to a float ten times, starting from 0.0, gives exactly 1.0.
  4. 4. The program below writes three lines and then calls os._exit(0). The output goes to a file. How many bytes are in the file? ``python import os import sys for i in range(1, 4): sys.stdout.write(f"this line is never flushed {i}\n") print("program ended") os._exit(0) ``
  5. 5. Which loop prints eleven values from 0.0 to 1.0 with no drift?

5 question(s) left on this page.