Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a new file in the Python Editor and copy-paste the following code into it: (This code is the same as the code in the

Create a new file in the Python Editor and copy-paste the following code into it: (This code is the same as the code in the "Creating a Module" section of Lecture 4) (When copying from a PDF file, indenting of code is likely to be removed - remember to add it back as needed!) Save the file as "convert.py", then create a new file and copy-paste the following code into it: (This code is the same as the code in the "Creating a Module" section of Lecture 4) Save this file (filename not important) in the same folder as convert.py, then run the code to test it. Once you've made sure that it is working, enhance convert.py to make it more useful in these ways: 1. Add a second parameter named "rounding" to each of the functions. The parameter should have a default value of 2, and should be used to round the result of the function. Test your work by calling the functions in your second file: convert.cm2inches(7) should return a value of 2.75 convert.m2yards(10, 1) should return a value of 10.9 2. Add a third parameter named "addUnit" to each of the functions. The parameter should have a default of False. If True is specified for the parameter when the function is called, the function should return a string of the result with the unit of measurement at the end, e.g. '2.75 inches' instead of 2.75. Test your work by calling the functions: convert.m2feet(5, 0, True) should return 16.0 feet convert.km2miles(2, addUnit=True) should return 1.24 miles MM_IN_INCH = 25.4 MM_IN_FOOT = 304.8 MM_IN_YARD = 914.4 MM_IN_MILE = 1609344 def cm2inches(cm): return cm * 0.393 def m2feet(m): return m * 3.281 def m2yards(m): return m * 1.094 def km2miles(km): return km * 0.621 Python import convert print('20 metres is', convert.m2feet(20), 'feet.') print('4 miles is', convert.MM_IN_MILE * 4, 'millimetres.')

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Calculus Early Transcendentals

Authors: James Stewart, Daniel K. Clegg, Saleem Watson, Lothar Redlin

9th Edition

1337613924, 978-1337613927

More Books

Students also viewed these Mathematics questions

Question

India has a federal system of government with a strong........?

Answered: 1 week ago

Question

Famous theory poverty and un british rule in India?

Answered: 1 week ago

Question

The Unicef was awarded the Nobel peace prize in the year........?

Answered: 1 week ago

Question

Who heads the council of ministers?

Answered: 1 week ago