Photo AI
Question 5
A program is being created to convert the data capacity of a storage device into a different measure. The function, calculate(), takes the measurement (e.g. gigabyt... show full transcript
Step 1
Answer
To complete the function calculate
, we must ensure that conversions for gigabytes, megabytes, kilobytes, and bytes are accurately represented. Here’s how:
function calculate(measurement, number)
if measurement == "gigabytes" then
value = number * 1024 * 1024 * 1024 * 8
elseif measurement == "megabytes" then
value = number * 1024 * 1024 * 8
elseif measurement == "kilobytes" then
value = number * 1024 * 8
elseif measurement == "bytes" then
value = number * 8
else
return -1
endif
return value
endfunction
Report Improved Results
Recommend to friends
Students Supported
Questions answered