Skip to content

Commit f2c9a1d

Browse files
committed
Working Version 2 of Unit converter
1 parent a0a2633 commit f2c9a1d

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

code/kelin/Unit-converter.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# kelin-lab02-unit-converter
2+
3+
# Version 1
4+
# Ask the user for the number of feet, and print out the equivalent distance in meters. Hint: 1 ft is 0.3048 m.
5+
6+
feet_to_meters = {'ft': 0.3048}
7+
8+
number_feet = input("\nPlease enter the number of feet: ")
9+
10+
number_feet = int(number_feet)
11+
12+
meters = (feet_to_meters['ft'] * number_feet)
13+
14+
print(meters)
15+
16+
# Version 2
17+
18+
# Allow the user to also enter the units. Then depending on the units, convert the distance into meters. The units we'll allow are feet, miles, meters, and kilometers.
19+
20+
# 1 ft is 0.3048 m
21+
# 1 mi is 1609.34 m
22+
# 1 m is 1 m
23+
# 1 km is 1000 m
24+
# Below is some sample input/output:
25+
26+
# > what is the distance? 100
27+
# > what are the units? mi
28+
# > 100 mi is 160934 m
29+
30+
meter = {
31+
"ft": 0.3048,
32+
"mi": 1609.34,
33+
"m": 1,
34+
"km": 1000
35+
}
36+
37+
number = input("Enter the distance: ")
38+
unit = input("Enter the unit - ft - mi - m - km: ")
39+
40+
41+
42+
43+
44+
45+
46+

0 commit comments

Comments
 (0)