Question: PYTHON The purpose of this part is to create a calculator that converts between units: centimeters (cm), inches (in), yards (yd), meters (m), kilometers (km),

PYTHON

The purpose of this part is to create a calculator that converts between units: centimeters (cm), inches (in), yards (yd), meters (m), kilometers (km), and miles (mi).

It will ask the user for the type of unit the input is given as, the desired output units, and the quantity to be converted. It will then print out the answer in a user-friendly way. Users are expected to respond with one of the six strings "cm", "in", "yd", "m", "km", or "mi" to the first two questions.

For example, if the user wants to convert 10 miles to kilometers, the program's output would be:

10.0 mi equals 16.0934 km

Since there are a lot of combinations between the types of units, we want to design an algorithm that minimizes our work. The program should not calculate every combination of units (that would be 36 different possibilities). Instead we can first convert all input units to meters, and then convert the intermediate meter units to the desired output units.

Use this table to determine the conversion to/from meters:

1 cm is 0.01 m

1 yd is 0.9144 m

1 in is 0.0254 m

1 mi is 1609.34 m

1 km is 1000 m

In other words, to convert from cm to m, you would multiply the quantity in cm by 0.01. The other way around, going from m to cm, you would divide by 0.01. Likewise for the other units.

Here's what the output of your program should look like when running correctly:

Enter input units (km/m/cm/mi/yd/in): yd

Enter output units (km/m/cm/mi/yd/in): cm

Enter quantity to convert: 10 10.0 yd equals 914.4 cm

As you can see, the user has given the answer "yd" to input units, the answer "cm" to output units, and "10" as the quantity. The program then calculated that 10 yards is equivalent to 914.4 cm. What you don't see here is the intermediate step of converting 10 yards to meters (9.144) (and after which 9.144 meters was converted to 914.4 cm).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!