Question: Part 2A: Building upon an Existing Solution I need to turn my current code into value returning functions and also put the functions in an
Part 2A: Building upon an Existing Solution
I need to turn my current code into value returning functions and also put the functions in an external module. Below is the instrutions from my professor.
**********************************************
For this portion of the lab, you will reuse the program you wrote in Lab 5 Part 1. Redesign this solution in the following manner:
All of the functions used must now be value returning functions.
Put the functions in an external module and let the main program import the module. Save the external module with .py extension.
Attatched below is the code I have so far, thanks for the help!
************************
def main():
miles = float(input('William, how many miles do you want to convert to kilometers? '))
MilesToKm(miles)
fahrenheit = float(input('William, what degrees fahrenheit do you want to convert to celsius? '))
FahToCel(fahrenheit)
gallons = float(input('William, how many gallons do you want to convert to liters? '))
GalToLit(gallons)
pounds = float(input('William, how many pounds do you want to convert to kilograms? '))
PoundsToKg(pounds)
inches = float(input('William, how many inches do you want to convert to centimeters? '))
InchesToCm(inches)
def MilesToKm(miles):
counter = 0
while miles < 0:
print("'ERROR - Negative Value [ENDING PROGRAM]")
miles = float(input("Enter the correct value for miles "))
counter+=1
if counter > 2:
break
if counter <= 2:
kilometers= miles * 1.6
print("The distance in kilometers is: ", kilometers)
else:
print("Exceeded error count")
def FahToCel(fahrenheit):
counter1 = 0
while fahrenheit < 0:
print("'ERROR - Negative Value [ENDING PROGRAM]")
fahrenheit = float(input("Enter the correct value for fahrenheit "))
counter1+=1
if counter1 > 2:
break
if counter1 <= 2:
celsius = (fahrenheit - 32) * 5/9
print("The degrees in celsius is: ", celsius)
else:
print("Exceeded error count")
def GalToLit(gallons):
counter2 = 0
while gallons < 0:
print("'ERROR - Negative Value [ENDING PROGRAM]")
gallons = float(input("Enter the correct value for gallons "))
counter2+=1
if counter2 > 2:
break
if counter2 <= 2:
liters = gallons * 3.9
print("The amount in liters is: ", liters)
else:
print("Exceeded error count")
def PoundsToKg(pounds):
counter3 = 0
while pounds < 0:
print("'ERROR - Negative Value [ENDING PROGRAM]")
pounds = float(input("Enter the correct value for pounds "))
counter3+=1
if counter3 > 2:
break
if counter3 <= 2:
kilograms = pounds * 0.45
print("The weight in kilograms is: ", kilograms)
else:
print("Exceeded error count")
def InchesToCm(inches):
counter4 = 0
while inches < 0:
print("'ERROR - Negative Value [ENDING PROGRAM]")
inches = float(input("Enter the correct value for miles "))
counter4+=1
if counter4 > 2:
break
if counter4 <= 2:
centimeters = inches * 2.54
print("The distance in centimeters is: ", centimeters)
else:
print("Exceeded error count")
main()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
