Skip to content

Instantly share code, notes, and snippets.

View NeOneSoft's full-sized avatar
🏠
Working from home

Gonzalo Romero NeOneSoft

🏠
Working from home
View GitHub Profile
@NeOneSoft
NeOneSoft / gist:ab1bfbdff977962d20f3e9ed1a865f7c
Created August 30, 2020 02:59
Elementary Robotics: Write a function in Python called ‘humanSize’ that takes a non-negative number of bytes and returns a string with the equivalent number of ‘kB’, ‘MB’, ‘GB’, ‘TB’, ‘PB’, ‘EB’, ‘ZB’, or ‘YB’, between [0, 1000), with at most 1 digit of precision after the decimal. If the number of bytes is >= 1000 YB, return this number of YB, …
class HumanSize:
def bytes_converter(self, bases: list, exponents: list) -> list:
return [base / exp for base, exp in zip(bases, exponents)]
def num_Range(self, number: float) -> bool:
return 0 < number < 1000
def humanSize(self, number: int) -> str:
exponents = [10 ** x for x in range(3, 25, 3)]
data = self.bytes_converter([number] * 8, exponents)