Skip to content

Commit 2060705

Browse files
Update 02 Unit Converter
1 parent 4230350 commit 2060705

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

1 Python/labs/02 Unit Converter

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ Lab 02: Unit Converter
22
This lab will involve writing a program that allows the user to convert a number between units.
33

44
Version 1
5-
Ask the user for the number of feet, and print out the equivalent distance in meters. Hint: 1 ft is 0.3048 m. So we can get the output in meters by multiplying the input distance by 0.3048. Below is some sample input/output.
5+
Ask the user for the number of feet, and print out the equivalent distance in meters. Hint: 1 ft is 0.3048 m. So we can get the output in meters by multiplying
6+
the input distance by 0.3048. Below is some sample input/output.
67

78
> what is the distance in feet? 12
89
> 12 ft is 3.6576 m
@@ -26,16 +27,19 @@ Add support for yards, and inches.
2627
Version 4 - optional
2728
Now we'll ask the user for the distance, the starting units, and the units to convert to.
2829

29-
You can think of the values for the conversions as elements in a matrix, where the rows will be the units you're converting from, and the columns will be the units you're converting to. Along the horizontal, the values will be 1 (1 meter is 1 meter, 1 foot is 1 foot, etc).
30+
You can think of the values for the conversions as elements in a matrix, where the rows will be the units you're converting from, and the columns will be the
31+
units you're converting to. Along the horizontal, the values will be 1 (1 meter is 1 meter, 1 foot is 1 foot, etc).
3032

3133
ft mi m km
3234
ft 1 0.3048
3335
mi 1 1609.34
3436
m 1/0.3048 1/1609.34 1 1/1000
3537
km 1000 1
36-
But instead of filling out that matrix, and checking for each pair of units (if from_units == 'mi' and to_units == 'km'), we can just convert any unit to meters, then convert the distance in meters to any other unit.
38+
But instead of filling out that matrix, and checking for each pair of units (if from_units == 'mi' and to_units == 'km'), we can just convert any unit to meters,
39+
then convert the distance in meters to any other unit.
3740

38-
Furthermore you can convert them from meters by dividing a distance (in meters) by those same values used above. So first convert from the input units to meters, then convert from meters to the output units.
41+
Furthermore you can convert them from meters by dividing a distance (in meters) by those same values used above. So first convert from the input units to meters,
42+
then convert from meters to the output units.
3943

4044
Below is some sample input/output:
4145

0 commit comments

Comments
 (0)