-
Notifications
You must be signed in to change notification settings - Fork 68
/
length.py
51 lines (36 loc) · 1.09 KB
/
length.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--inch-to-cm', type=float, dest="inch_to_cm")
parser.add_argument('--cm-to-inch', type=float, dest="cm_to_inch")
# args parser for cm to mm converter
parser.add_argument('--cm-to-mm', type=float, dest="cm_to_mm")
args = parser.parse_args()
def main():
inch_to_cm_helper()
cm_to_inch_helper()
cm_to_mm_helper()
# helper function for checking args for cm_to_mm function
def cm_to_mm_helper():
cm_mm = args.cm_to_mm
if (cm_mm):
cm_to_mm(cm_mm)
# Helper functions to check if the arg exists or not
def inch_to_cm_helper():
inch = args.inch_to_cm
if inch:
inch_to_cm(inch)
def cm_to_inch_helper():
cm = args.cm_to_inch
if cm:
cm_to_inch(cm)
# Converter functions
def inch_to_cm(inch):
print(f'{inch} inch in cm is: {inch*2.54} cm')
def cm_to_inch(cm):
print(f'{cm} cm in inch is: {cm/2.54} inch')
# function to convert cm to mm
def cm_to_mm(cm_mm):
print(f'{cm_mm}cm in mm is: {cm_mm*10} mm')
if __name__ == "__main__":
main()
# i didn't add any changes :>