Question: 3. Implement units.py Do you remember fluid unit conversions from middle school? If not, here's a quick recap: 1 US fluid ounce = 8 US

3. Implement units.py

Do you remember fluid unit conversions from middle school? If not, here's a quick recap:

1 US fluid ounce = 8 US fluid drams 1 US liquid quart = 32 US fluid ounces 1 US liquid gallon = 4 US liquid quarts 

In this problem, you will implement functions to convert fluid quantities from one unit to another. All the conversion factors that you need have been specified above for your reference. This problem will demonstrate how you can use functions to break a complex problem into smaller sub-problems.

3a. Convert ounces to drams (2 points)

Your task is to implement a function with the following signature:

def ounces_to_drams(ounces:float) -> float 

The function should take as input a float ounces and return the corresponding quantity in drams.

Example:

ounces_to_drams(8) # This should return 64 ounces_to_drams(2.5) # This should return 20 

3b. Convert drams to ounces (2 points)

Your task is to implement a function with the following signature:

def drams_to_ounces(drams:float) -> float 

The function should take as input a float drams and return the corresponding quantity in ounces.

Example:

drams_to_ounces(8) # This should return 1 drams_to_ounces(120.84) # This should return 15.105 

3c. Convert quarts to ounces (2 points)

Your task is to implement a function with the following signature:

def quarts_to_ounces(quarts:float) -> float 

The function should take as input a float quarts and return the corresponding quantity in ounces.

Example:

quarts_to_ounces(8) # This should return 256 quarts_to_ounces(2.5) # This should return 80 

3d. Convert ounces to quarts (2 points)

Your task is to implement a function with the following signature:

def ounces_to_quarts(ounces:float) -> float 

The function should take as input a float ounces and return the corresponding quantity in quarts.

Example:

ounces_to_quarts(64) # This should return 2 ounces_to_quarts(120.84) # This should return 3.77625 

3e. Convert gallons to quarts (2 points)

Your task is to implement a function with the following signature:

def gallons_to_quarts(gallons:float) -> float 

The function should take as input a float gallons and return the corresponding quantity in quarts.

Example:

gallons_to_quarts(64) # This should return 256 gallons_to_quarts(120.84) # This should return 483.36 

3f. Convert quarts to gallons (2 points)

Your task is to implement a function with the following signature:

def quarts_to_gallons(quarts:float) -> float 

The function should take as input a float quarts and return the corresponding quantity in gallons.

Example:

quarts_to_gallons(72) # This should return 18 quarts_to_gallons(120.84) # This should return 30.21 

3g. Convert gallons to drams (2 points)

Your task is to implement a function with the following signature:

def gallons_to_drams(gallons:float) -> float 

The function should take as input a float gallons and return the corresponding quantity in drams.

Example:

gallons_to_drams(12) # This should return 12288 gallons_to_drams(0.078) # This should return 79.872 

Hint: Re-use the functions in 3a. - 3f.

3h. Convert drams to gallons (2 points)

Your task is to implement a function with the following signature:

def drams_to_gallons(drams:float) -> float 

The function should take as input a float drams and return the corresponding quantity in gallons.

Example:

drams_to_gallons(250) # This should return 0.244141 drams_to_gallons(2999) # This should return 2.928711 

Hint: Re-use the functions in 3a. - 3f.

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!