I know there was a problem with today’s coding challenge, but disregarding that. How would you write this to be more readable. I had a couple ideas on how to do the conversions but this seemed to be the most efficient but not pleasing aswell. Additionally all the variables are really similar in name so it can be a little confusing.
def number_of_videos(video_size, video_unit, drive_size, drive_unit):
th = 1000
v_size = {"B": 1, "KB": th, "MB": th*th, "GB":th*th*th}
d_size = {"GB": th*th*th, "TB": th*th*th*th}
if video_unit not in v_size:
return "Invalid video unit"
elif drive_unit not in d_size:
return "Invalid drive unit"
v_space = video_size * v_size[video_unit]
d_space = drive_size * d_size[drive_unit]
return d_space // v_space
print(number_of_videos(1.5, "GB", 2.2, "TB"))