Reconciling written characters and stored bytes

An engineer generates a temperature report with the following Python 3 code. All writes succeed, and the file is closed before its size is measured.


Python
records = [("P1", 2.5), ("P2", 11.0)]

with open("check.txt", "w", encoding="utf-8", newline="\r\n") as target:
    reported = target.write("probe,temperature (°C)\n")
    for label, temperature in records:
        reported += target.write(f"{label},{temperature:.2f}\n")


With this newline setting, each \n passed to write is stored as \r\n. In UTF-8, ° occupies two bytes; every other character used in this output occupies one byte. The file contains no additional prefix bytes.


Find the final value of reported, measured in characters, and the resulting file size, measured in bytes. Give both answers as exact integers.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Text File Operations Questions: