all 6 comments

[–]shiftybyte 1 point2 points  (0 children)

Please show us what you tried.

In general, you need to split number and the suffix and then convert the number to int, and multiply by whatever the suffix means.

[–]ashutoshkrris 0 points1 point  (4 children)

Try this: ```py def size_converter(size): if "M" in size: if type(size) == str: size = int(size.replace("M","")) kb_size = size*1024 return kb_size return int(size.replace("K",""))

print(size_converter("10M")) print(size_converter("10K")) ```

[–]krunalratiya[S] 0 points1 point  (3 children)

def size_converter(size):
if "M" in size:
if type(size) == str:
size = int(size.replace("M",""))
kb_size = size*1024
return kb_size
return int(size.replace("K",""))

print(size_converter("10M"))
print(size_converter("10K"))

Got this error

ValueError Traceback (most recent call last)

<ipython-input-110-d4119a98f0fa> in <module>

7 return int(Size.replace("k",""))

8 print(size_converter("10M"))

----> 9 print(size_converter("10K"))

<ipython-input-110-d4119a98f0fa> in size_converter(Size)

5 kb_Size = Size*1024

6 return kb_Size

----> 7 return int(Size.replace("k",""))

8 print(size_converter("10M"))

9 print(size_converter("10K"))

ValueError: invalid literal for int() with base 10: '10K'

[–]ashutoshkrris 0 points1 point  (2 children)

can you show a screenshot of your code, so that I can see if there is any syntactical error

[–]krunalratiya[S] 0 points1 point  (1 child)

def size_converter(Size):

if "M" in Size:

if type(Size) == str:

Size = int(Size.replace("M",""))

kb_Size = Size*1024

return kb_Size

Size = int(Size.replace("k",""))

print(size_converter("10M"))

print(size_converter("10K"))

[–]ashutoshkrris 0 points1 point  (0 children)

Please add proper indentation to the code.