Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In a file called convert_metric.py, write a Python function called metric_conversion that will convert metric measurements to/from imperial units as follows: pounds to/from kilos
In a file called convert_metric.py, write a Python function called metric_conversion that will convert metric measurements to/from imperial units as follows: pounds to/from kilos ounces to/from grams miles to/from kilometers inches to/from centimeters Your function should do the following: take in two values: a floating point measurement and a separate "units" string from the following set: {'pounds', 'ounces', 'miles', 'inches', 'kilos', 'grams', 'kilometers', 'centimeters'} then convert the value to the corresponding units and output both the converted value and its units. Use the built-in format() function to print out 4 digits to the right of the decimal point. (i.e. 5.1234) If the "units" string is not recognized (not in those specified), your program should produce an error message and terminate the program from there. Example: Enter value: 1.0 Enter units: centimeters 0.3937 inches Enter value: 10 Enter units: ounces 283.4952 grams Enter value: Enter units: 100 grams 100 grams is not a valid unit.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Here is the code for the convertmetricpy file implementing the metricconversion function python def ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started