-
-
Save AnisahTiaraPratiwi/f1bd07dd033ec9941fe68104c605a892 to your computer and use it in GitHub Desktop.
def calculate_storage(filesize): | |
block_size = 4096 | |
# Use floor division to calculate how many blocks are fully occupied | |
full_blocks = filesize//4096 | |
# Use the modulo operator to check whether there's any remainder | |
partial_block_remainder = filesize%4096 | |
# Depending on whether there's a remainder or not, return | |
# the total number of bytes required to allocate enough blocks | |
# to store your data. | |
if partial_block_remainder > 0: | |
return 4096*(full_blocks+1) | |
return full_blocks*4096 | |
print(calculate_storage(1)) # Should be 4096 | |
print(calculate_storage(4096)) # Should be 4096 | |
print(calculate_storage(4097)) # Should be 8192 | |
print(calculate_storage(6000)) # Should be 8192 |
def calculate_storage(filesize):
block_size = 4096
# Use floor division to calculate how many blocks are fully occupied
full_blocks = filesize//block_size
# Use the modulo operator to check whether there's any remainder
partial_block_remainder = filesize%block_size
# Depending on whether there's a remainder or not, return
# the total number of bytes required to allocate enough blocks
# to store your data.
if partial_block_remainder > 0:
return block_size+full_blocks*block_size
return block_size
print(calculate_storage(1)) # Should be 4096
print(calculate_storage(4096)) # Should be 4096
print(calculate_storage(4097)) # Should be 8192
print(calculate_storage(6000)) # Should be 8192
def calculate_storage(filesize):
block_size = 4096
# Use floor division to calculate how many blocks are fully occupied
full_blocks = filesize//block_size
# Use the modulo operator to check whether there's any remainder
partial_block_remainder = filesize%block_size
# Depending on whether there's a remainder or not, return
# the total number of bytes required to allocate enough blocks
# to store your data.
if partial_block_remainder > 0:
return block_size*(full_blocks+1)
return full_blocks*block_size
print(calculate_storage(1)) # Should be 4096
print(calculate_storage(4096)) # Should be 4096
print(calculate_storage(4097)) # Should be 8192
print(calculate_storage(6000)) # Should be 8192
I know this won't make much of a sense & its wrong method too
Can someone guide me?
`def calculate_storage(filesize):
block_size = 4096
# Use floor division to calculate how many blocks are fully occupied
full_blocks = block_size // filesize
# Use the modulo operator to check whether there's any remainder
partial_block_remainder = full_blocks
# Depending on whether there's a remainder or not, return
# the total number of bytes required to allocate enough blocks
# to store your data.
if partial_block_remainder > 0:
return 4096
return 8192
print(calculate_storage(1)) # Should be 4096
print(calculate_storage(4096)) # Should be 4096
print(calculate_storage(4097)) # Should be 8192
print(calculate_storage(6000)) # Should be 8192`
Who knows, what number should we assign to variable so that it could print(3)?
number = 10
if number > 11:
print(0)
elif number != 10:
print(1)
elif number >= 20 or number < 12:
print(2)
else:
print(3)
These above conditions don't seem to be perfect.
These above conditions don't seem to be perfect.
These conditions above are from google certification course.
def calculate_storage(filesize):
block_size = 4096
# Use floor division to calculate how many blocks are fully occupied
full_blocks = filesize//block_size
# Use the modulo operator to check whether there's any remainder
partial_block_remainder = filesize%block_size
# Depending on whether there's a remainder or not, return
# the total number of bytes required to allocate enough blocks
# to store your data.
if partial_block_remainder > 0:
return block_sizefull_blocks+block_size
return block_sizefull_blocks
print(calculate_storage(1)) # Should be 4096
print(calculate_storage(4096)) # Should be 4096
print(calculate_storage(4097)) # Should be 8192
print(calculate_storage(6000)) # Should be 8192
Who knows, what number should we assign to variable so that it could print(3)?
number = 10 if number > 11: print(0) elif number != 10: print(1) elif number >= 20 or number < 12: print(2) else: print(3)
The above condition Solution is 2 because number is less then 12 match condition , The or operator returns True if either operand is true.
def calculate_storage(filesize)
:
block_size = 4096
# Use floor division to calculate how many blocks are fully occupied
full_blocks = block_size // filesize
# Use the modulo operator to check whether there's any remainder
partial_block_remainder = block_size % filesize
# Depending on whether there's a remainder or not, return
# the total number of bytes required to allocate enough blocks
# to store your data.
if partial_block_remainder > 0:
return block_size * 2
return block_size
print(calculate_storage(1)) # Should be 4096
print(calculate_storage(4096)) # Should be 4096
print(calculate_storage(4097)) # Should be 8192
print(calculate_storage(6000)) # Should be 8192
def calculate_storage(filesize):
block_size = 4096
# Use floor division to calculate how many blocks are fully occupied
full_blocks = filesize // block_size
# Use the modulo operator to check whether there's any remainder
partial_block_remainder = filesize % block_size
# Depending on whether there's a remainder or not, return
# the total number of bytes required to allocate enough blocks
# to store your data.
if partial_block_remainder > 0:
return block_size + (full_blocks * block_size)
return block_size*full_blocks
print(calculate_storage(1)) # Should be 4096
print(calculate_storage(4096)) # Should be 4096
print(calculate_storage(4097)) # Should be 8192
print(calculate_storage(6000)) # Should be 8192
### Don't make it too important!
my code:
`def calculate_storage(filesize):
block_size = 4096
# Use floor division to calculate how many blocks are fully occupied
#full_blocks = (filesize) // block_size
# Use the modulo operator to check whether there's any remainder
partial_block_remainder = (filesize -1) // block_size
# Depending on whether there's a remainder or not, return
# the total number of bytes required to allocate enough blocks
# to store your data.
if partial_block_remainder > 0:
return (block_size * (partial_block_remainder +1))
return block_size
print(calculate_storage(1)) # Should be 4096
print(calculate_storage(4096)) # Should be 4096
print(calculate_storage(4097)) # Should be 8192
print(calculate_storage(6000)) # Should be 8192`
def calculate_storage(filesize):
block_size = 4096
# Use floor division to calculate how many blocks are fully occupied
full_blocks = (filesize) // block_size
# Use the modulo operator to check whether there's any remainder
partial_block_remainder = (filesize -1) // block_size
# Depending on whether there's a remainder or not, return
# the total number of bytes required to allocate enough blocks
# to store your data.
if partial_block_remainder > 0:
return 8192
return 4096
print(calculate_storage(1)) # Should be 4096
print(calculate_storage(4096)) # Should be 4096
print(calculate_storage(4097)) # Should be 8192
print(calculate_storage(6000)) # Should be 8192
def calculate_storage(filesize):
block_size = 4096
# Use floor division to calculate how many blocks are fully occupied
full_blocks = (filesize + block_size) // block_size
# Use the modulo operator to check whether there's any remainder
partial_block_remainder = (filesize + block_size) % block_size
# Depending on whether there's a remainder or not, return
# the total number of bytes required to allocate enough blocks
# to store your data.
if partial_block_remainder > 0:
return full_blocks * 4096
return block_size
print(calculate_storage(1)) # Should be 4096
print(calculate_storage(4096)) # Should be 4096
print(calculate_storage(4097)) # Should be 8192
print(calculate_storage(6000)) # Should be 8192
@Sojiknight Thank you!
Uh oh!
There was an error while loading. Please reload this page.