-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquantity.py
More file actions
38 lines (33 loc) · 721 Bytes
/
quantity.py
File metadata and controls
38 lines (33 loc) · 721 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from sys import argv
def humanSize(bytes_value: int):
divided_by = 1000
sizes = [
"KB",
"MB",
"GB",
"TB",
"PB",
"EB",
"ZB",
"YB"
]
pointer = 0
result = bytes_value
while(True):
result = result/divided_by
if result <divided_by or pointer==len(sizes)-1:
break
pointer+=1
return f"{result:0.1f}{sizes[pointer]}"
if len(argv)<2:
print (
"""
The command need to be executed with one argument, example:
python quantity.py 546432423423
""")
exit(1)
if not argv[1].isnumeric():
print("the parameter must be numeric")
exit(1)
value = float(argv[1])
print(humanSize(value))