jeudi 23 janvier 2020

Doing conditionals practice and I am a bit unsure what to return here

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 storage size needed for a given filesize? 5.

def calculate_storage(filesize):
    block_size = 4096
    # Use floor division to calculate how many blocks are fully occupied
    full_blocks = (block_size * 2) // filesize
    # Use the modulo operator to check whether there's any remainder
    partial_block = block_size % filesize
    # Depending on whether there's a remainder or not, return the right number.
    if partial_block > 0:
        return 
    else:
      return 
# Unsure what to return here? ??
print(calculate_storage(1))    # Should be 4096
print(calculate_storage(4096)) # Should be 4096
print(calculate_storage(4097)) # Should be 8192

Aucun commentaire:

Enregistrer un commentaire