Skip to content
Advertisement

What’s wrong with this storage calculator?

I’m new to python, and this question appeared on a course.

JavaScript

This was my answer. The question was this: If a filesystem has a block size of 4096 bytes, this means that a file comprised of only one byte will still use 4096 bytes of storage. A file made up of 4097 bytes will use 4096*2=8192 bytes of storage. Knowing this, can you fill in the gaps in the calculate_storage function below, which calculates the total number of bytes needed to store a file of a given size?

With the base code here:

JavaScript

The Incorrect statement was this: Not quite. One concept to keep in mind is the difference between float division (/) and floor division (//). Floor division rounds down to the nearest whole number, which is useful for this question. Use filesize // block_size to get the amount of full blocks. Something else to remember here is the format of modulo arithmetic. The divisor is always to the right of the modulo operator. E.g.- 2 = 6 % 4 <- This is the divisor.

Advertisement

Answer

you need to multiply the return values by the block size:

JavaScript

returns:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement