Question: Exercise 2 In a previous lab, you wrote Python code that converted miles-per-Imperial gallon to litres-per- 100 km. In this exercise, you'll reimplement this code

 Exercise 2 In a previous lab, you wrote Python code that

Exercise 2 In a previous lab, you wrote Python code that converted miles-per-Imperial gallon to litres-per- 100 km. In this exercise, you'll reimplement this code as a function. Step 1: Create a new editor window (File->New) and save it as a file named lab3ex2.py. REMEMBER: Only type lab3ex2. Do not type lab3ex2.py Step 2: Type these two assignment statements and the function header. (One Imperial gallon is equal to approximately 4.54609 litres and one mile is equal to approximately 1.60934 km. Recall that the names of constant values in Python are, by convention, usually written entirely in uppercase.) LITRES_PER_GALLON = 4.54609 KMS_PER_MILE = 1.60934 def convert_to_litres_per_100_km(mpg): Write the body of the function to complete the function definition. Step 3: Save the code, then click Run. Correct any syntax errors. Step 4: Use the same procedure as in Exercise 1 to test your function (See Exercise 1, Step 5 to 13). Your call expressions should test: The value returned by the function when the argument is 32 The value returned by the function when the argument is 0 Whether the function works for integer arguments and real number arguments

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!