Respuesta :
Answer:
Python code given below
Explanation:
def calculate_storage(filesize):
block_size = 4096
full_blocks = filesize // block_size
partial_block = filesize % block_size
if partial_block > 0:
return (full_blocks + 1) * block_size
return filesize
print(calculate_storage(1))
print(calculate_storage(4096))
print(calculate_storage(4097))
The required function written in python to calculate the required storage for any given file size is written thus :
def calculate_storage(filesize):
block_size = 4096
full_block = filesize // block_size
partial_block = full_block % block_size
if partial_block > 0:
return (1 + full_block)*block_size
else:
return full_block * block_size
Code breakdown :
- def calculate_storage(filesize):
#initiates a function named calculate_storage and takes only one argument.
- block_size = 4096
# size of a block is assigned to the variable block_size
- full_block = filesize // block_size
# returns the largest possible integer, which is the size of a full block
- partial_block = full_block % block_size
# the remainder value
- if partial_block > 0:
# checks if the partial_block value is greater than 0
- return (1 + full_block)*block_size
# if true treat the remainder as a full block and multiply
- else:
- return full_block * block_size
# if false only multiply the full_block by the block_size
Learn more : https://brainly.com/question/14786286?referrer=searchResults