/
main.py
executable file
·39 lines (28 loc) · 1.09 KB
/
main.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
#!/usr/bin/env python
# Command line script to convert a single number to and from several units
import argparse
from src.convert import kilometers_to_miles, miles_to_kilometers,\
years_to_minutes, minutes_to_years, f_to_c, c_to_f
# Parse command line args
parser = argparse.ArgumentParser()
parser.add_argument('value', type=float, help="The number to be converted")
args = parser.parse_args()
# Perform conversions
# km to miles
to_miles = kilometers_to_miles(args.value)
print("{0} kilometers is {1} miles".format(args.value, to_miles))
# miles to km
to_km = miles_to_kilometers(args.value)
print("{0} miles is {1} kilometers".format(args.value, to_km))
# years to minutes
to_minutes = years_to_minutes(args.value)
print("{0} years is {1} minutes".format(args.value, to_minutes))
# minutes to years
to_years = minutes_to_years(args.value)
print("{0} minutes is {1} years".format(args.value, to_years))
# farenheit to celcius
to_f = f_to_c(args.value)
print("{0} F is {1} C".format(args.value, to_f))
# celcius to farenheit
to_c = c_to_f(args.value)
print("{0} C is {1} F".format(args.value, to_c))