Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

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

Oracle 12c SQL

Authors: Joan Casteel

3rd edition

1305251032, 978-1305251038

More Books

Students also viewed these Databases questions