Python Program to Convert Memory Size in MB.

Memory Size Conversion in MB Python Program

This python program is used to convert the memory size in MB from KB and GB.

# Python program to convert memory size in MB
#!/usr/bin/python

def convert_memory_unit_in_mb(mem_val):
    mem_info = mem_val.split(' ')
    unit = mem_info[1].strip(' \n').lower()
    mem_size = int(mem_info[0].strip(' '))
    if unit == 'kb':
        mem_size = mem_size / 1024
    elif unit =='gb':
        mem_size = mem_size * 1024
    return mem_size

if __name__ == '__main__':
    mem_val = str(input("Enter memory size:"));
    mem_size_mb = convert_memory_unit_in_mb(mem_val)
    print('Memory size in MB:' + str(mem_size_mb));

Output:
$ python memory-unit-converter.py 
Enter memory size:'34343535 GB'
Memory size in MB:35167779840
$ python memory-unit-converter.py 
Enter memory size:'34343535 KB'
Memory size in MB:33538

Privacy Policy  |  Copyright@2017 - All Rights Reserved.  |  Contact us   |  Report website issues in Github   |  Facebook page   |  Google+ page

Email Facebook Google LinkedIn Twitter
^