Biology, asked by prachikar76, 3 months ago

write python program to input data in megabyte and convert it into kilobyte

Answers

Answered by astha8191
2

Answer:

I am using a library that reads a file and returns its size in bytes.

This file size is then displayed to the end user; to make it easier for them to understand it, I am explicitly converting the file size to MB by dividing it by 1024.0 * 1024.0. Of course this works, but I am wondering is there a better way to do this in Python?

By better, I mean perhaps a stdlib function that can manipulate sizes according to the type I want. Like if I specify MB, it automatically divides it by 1024.0 * 1024.0. Somethign on these lines.

Answered by varshashinde716
0

Answer:

I am trying to write an application to convert bytes to kb to mb to gb to tb. Here's what I have so far:

def size_format(b): if b < 1000: return '%i' % b + 'B' elif 1000 <= b < 1000000: return '%.1f' % float(b/1000) + 'KB' elif 1000000 <= b < 1000000000: return '%.1f' % float(b/1000000) + 'MB' elif 1000000000 <= b < 1000000000000: return '%.1f' % float(b/1000000000) + 'GB' elif 1000000000000 <= b: return '%.1f' % float(b/1000000000000) + 'TB'

Explanation:

plz mark me as brainliest

Similar questions
Math, 1 month ago