How many charcters would be in each line printed by this code, if one character is 2 bytes? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How many charcters would be in each line printed by this code, if one character is 2 bytes?

file =open("filename.text", "r") for i in range(21): print(file.read(4)) file.close()

17th Oct 2023, 1:34 AM
Jannah Mae Ynion
Jannah Mae Ynion - avatar
2 Answers
0
Each line printed by this code will have 84 characters, and the total data read from the file is 168 bytes. -Lmk if this helped!-
17th Oct 2023, 2:08 AM
xJAYOx
xJAYOx - avatar
0
xJAYOx, you misread the question, also made a wrong calculation. It is the exercise in Python Developer, previous slide says: "Each ASCII character is 1 byte" So print(file.read(1)) prints ONE character, print(file.read(5)) prints FIVE characters and so on. What would happen if each character is 2 bytes? It is a simple division calculation.
17th Oct 2023, 2:22 AM
Wong Hei Ming
Wong Hei Ming - avatar