Question
(Based on Python) In this lab, you will write a function that convert any imperial measurements within a sentence to metric. For example, if the
(Based on Python)
In this lab, you will write a function that convert any imperial measurements within a sentence to metric. For example, if the original string said 'This pencil was 2 inches long, then the function will return 'This pencil was 5 centimeters long'.
Tasks
1. Write a function convertString that will "translate" imperial measurements within a sentence to metric. It takes in one parameter sentence which is a descriptive sentence with an imperial measurement. It will return the same sentence but with the imperial measurement replaced with the metric equivalent. Use the methods from the RegEx (regular expression) module to modify the string.
- Convert inches to centimeters, feet and yards to meters, miles to kilometers, and F to C (Fahrenheit to Celsius).
- The function needs to also check for singular inputs like "foot" and "inch" and convert them to the metric units. The metric units can all be plural (meters, centimeters,...)
- Make sure the function can handle multiple values with different conversion factors in one sentence.
- Round the output value to the same number of significant figures which are originally used.
2. Write a function which converts Fahreneht to Clesius. Use that function within the convertString function.
3. Produce a table with the converted units. (just the units without the values)
4. Add function comments.
5. Run your function to test it and leave the outputs in your submitted notebook. Use the test cases provided below.
6. The code has been started for you.
orint ( convertstring( ' 1 foot.' ) ) \#.3 meters orint( convertstring('This pencil was 2.8 inches long, but the tape measure is 25 yards.' )) \# This pencil was 7. centimeters long, but the tape measure is 23 meters. Test for 3. task rint( convertstring( 'I walked 26 miles and 400 feet to school each day. At a temperature of 30F that was no fun.' ) )Step by Step Solution
There are 3 Steps involved in it
Step: 1
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