need help passing functions: ###################################################
ID: 3684844 • Letter: N
Question
need help passing functions:
##################################################################
def miles(miles, kilometers):
miles = int (input("Tell me how many miles you would like to convert:"))
# Error Check for Miles input
count =0
if (miles < 0):
for count in range (2):
print ("Invalid input Miles cannot be negative, please Enter again.")
count = count + 1
miles = float (input ('How many Miles? '))
print ("Miles Entered: ", miles)
while (miles < 0 and count >= 2):
print ("Invalid input Miles cannot be negative, Program will End.")
quit ()
else:
print ("Miles Entered: ", miles)
conv_fac = 1.6
kilometers = miles * float(conv_fac)
return (miles, kilometers)
##################################################################
def fahrenheit(fahrenheit,celsius):
fahrenheit = float (input ('Enter degree Fahrenheit: '))
# Error Check for Fahrenheit input
count =0
if (fahrenheit > 1000):
for count in range (2):
print ("Invalid input Fahrenheit Degree cannot be above 1000 degrees, please Enter again.")
count = count + 1
fahrenheit = float(input('Enter degree Fahrenheit: '))
print("Fahrenheit Degrees Entered: ", fahrenheit)
while(fahrenheit > 1000 and count >= 2):
print("Invalid input Fahrenheit cannot be negative, Program will End.")
quit()
else:
print("Fahrenheit Degrees Entered: ", fahrenheit)
conv_fac1 = (fahrenheit -32) * 5/9
celsius = conv_fac1
return (fahrenheit,celsius)
##################################################################
def gallons(gallons,liters):
gallons = float(input('How Many Gallons: '))
# Error Check for Gallons input
count =0
if(gallons < 0):
for count in range (2):
print("Invalid input Gallons cannot be negative, please Enter again.")
count = count + 1
gallons = float(input('How Many Gallons: '))
print("Gallons Entered: ", gallons)
while(gallons < 0 and count >= 2):
print("Invalid input Gallons cannot be negative, Program will End.")
quit()
else:
print("Gallons Entered: ", gallons)
conv_fac2 = 3.9
liters = gallons * conv_fac2
return (gallons,liters)
##################################################################
def pounds(pounds,kilograms):
pounds = float(input('How Many Pounds: '))
# Error Check for Pounds input
count =0
if(pounds < 0):
for count in range (2):
print("Invalid input Pounds cannot be negative, please Enter again.")
count = count + 1
pounds = float(input('How Many Pounds: '))
print("Pounds Entered: ", pounds)
while(Pounds < 0 and count >= 2):
print("Invalid input Pounds cannot be negative, Program will End.")
quit()
else:
print("Pounds Entered: ", pounds)
conv_fac3 = 0.45
kilograms = pounds * conv_fac3
return (pounds,kilograms)
##################################################################
def inches(inches,centimeters):
inches = float(input('How Many Inches: '))
# Error Check for Inches input
count =0
if (inches < 0):
for count in range (2):
print ("Invalid input Inches cannot be negative, please Enter again.")
count = count + 1
inches = float(input('How Many Inches: '))
print ("Inches Entered: ", inches)
while (inches < 0 and count >= 2):
print ("Invalid input Inches cannot be negative, Program will End.")
quit ()
else:
print ("Inches Entered: ", inches)
conv_fac4 = 2.54
centimeters = inches * conv_fac4
return (inches,centimeters)
##################################################################
def dollars(Dollars,GBP):
Dollars = float (input ('How Many Dollars: '))
# Error Check for Dollars input
count =0
if (Dollars < 0):
for count in range (2):
print ("Invalid input Dollars cannot be negative, please Enter again.")
count = count + 1
Dollars = float (input ('How Many Dollars: '))
print ("Dollars Entered: ", Dollars)
while (Dollars < 0 and count >= 2):
print ("Invalid input Dollars cannot be negative, Program will End.")
quit ()
else:
print ("Dollars Entered: ", Dollars)
conv_fac5 = 0.69
GBP = Dollars * conv_fac5
return (Dollars,GBP)
##################################################################
def display():
print('%0.3f Miles is equal to %0.3f Kilometers' %(miles,kilometers))
print('%0.1f degree Fahrenheit is equal to %0.1f degree Celsius' %(fahrenheit,celsius))
print('%0.3f Gallons is equal to %0.3f Liters' %(gallons,liters))
print('%0.3f Pounds is equal to %0.3f kilograms' %(pounds,kilograms))
print('%0.3f Inches is equal to %0.3f Centimeters' %(inches,centimeters))
print('%0.3f Dollars is equal to %0.3f GBP (British Pounds)' %(Dollars,GBP))
##################################################################
def main():
print("Hello this program will allow you to make conversions!")
print("You will be able to convert Miles, Temperature, Gallons,")
print("pounds, inches and US Dollars as well!")
mi = miles(miles, kilometers)
fd = fahrenheit()
ga = gallons()
lb = pounds()
ic = inches ()
da = dollars()
dis = display()
main()
Explanation / Answer
# changes are highlghted
##################################################################
def mile():
miles = int (input("Tell me how many miles you would like to convert: "))
# Error Check for Miles input
count =0
if (miles < 0):
for count in range (2):
print ("Invalid input Miles cannot be negative, please Enter again.")
count = count + 1
miles = float (input ('How many Miles? '))
print ("Miles Entered: ", miles)
while (miles < 0 and count >= 2):
print ("Invalid input Miles cannot be negative, Program will End.")
quit()
else:
print ("Miles Entered: ", miles)
conv_fac = 1.6
kilometers = miles * float(conv_fac)
return (miles, kilometers)
##################################################################
def fahrenheit():
fahrenheit = float (input ('Enter degree Fahrenheit: '))
# Error Check for Fahrenheit input
count =0
if (fahrenheit > 1000):
for count in range (2):
print ("Invalid input Fahrenheit Degree cannot be above 1000 degrees, please Enter again.")
count = count + 1
fahrenheit = float(input('Enter degree Fahrenheit: '))
print("Fahrenheit Degrees Entered: ", fahrenheit)
while(fahrenheit > 1000 and count >= 2):
print("Invalid input Fahrenheit cannot be negative, Program will End.")
quit()
else:
print("Fahrenheit Degrees Entered: ", fahrenheit)
conv_fac1 = (fahrenheit -32) * 5/9
celsius = conv_fac1
return (fahrenheit,celsius)
##################################################################
def gallons():
gallons = float(input('How Many Gallons: '))
# Error Check for Gallons input
count =0
if(gallons < 0):
for count in range (2):
print("Invalid input Gallons cannot be negative, please Enter again.")
count = count + 1
gallons = float(input('How Many Gallons: '))
print("Gallons Entered: ", gallons)
while(gallons < 0 and count >= 2):
print("Invalid input Gallons cannot be negative, Program will End.")
quit()
else:
print("Gallons Entered: ", gallons)
conv_fac2 = 3.9
liters = gallons * conv_fac2
return (gallons,liters)
##################################################################
def pounds():
pounds = float(input('How Many Pounds: '))
# Error Check for Pounds input
count =0
if(pounds < 0):
for count in range (2):
print("Invalid input Pounds cannot be negative, please Enter again.")
count = count + 1
pounds = float(input('How Many Pounds: '))
print("Pounds Entered: ", pounds)
while(Pounds < 0 and count >= 2):
print("Invalid input Pounds cannot be negative, Program will End.")
quit()
else:
print("Pounds Entered: ", pounds)
conv_fac3 = 0.45
kilograms = pounds * conv_fac3
return (pounds,kilograms)
##################################################################
def inches():
inches = float(input('How Many Inches: '))
# Error Check for Inches input
count =0
if (inches < 0):
for count in range (2):
print ("Invalid input Inches cannot be negative, please Enter again.")
count = count + 1
inches = float(input('How Many Inches: '))
print ("Inches Entered: ", inches)
while (inches < 0 and count >= 2):
print ("Invalid input Inches cannot be negative, Program will End.")
quit ()
else:
print ("Inches Entered: ", inches)
conv_fac4 = 2.54
centimeters = inches * conv_fac4
return (inches,centimeters)
##################################################################
def dollars():
Dollars = float (input ('How Many Dollars: '))
#Error Check for Dollars input
count =0
if (Dollars < 0):
for count in range (2):
print ("Invalid input Dollars cannot be negative, please Enter again.")
count = count + 1
Dollars = float (input ('How Many Dollars: '))
print ("Dollars Entered: ", Dollars)
while (Dollars < 0 and count >= 2):
print ("Invalid input Dollars cannot be negative, Program will End.")
quit ()
else:
print ("Dollars Entered: ", Dollars)
conv_fac5 = 0.69
GBP = Dollars * conv_fac5
return (Dollars,GBP)
##################################################################
def display(miles , kilometers, fahrenheit, celsius, gallons,liters,pounds,kilograms,inches,centimeters,Dollars,GBP):
print('%0.3f Miles is equal to %0.3f Kilometers' %(miles,kilometers))
print('%0.1f degree Fahrenheit is equal to %0.1f degree Celsius' %(fahrenheit,celsius))
print('%0.3f Gallons is equal to %0.3f Liters' %(gallons,liters))
print('%0.3f Pounds is equal to %0.3f kilograms' %(pounds,kilograms))
print('%0.3f Inches is equal to %0.3f Centimeters' %(inches,centimeters))
print('%0.3f Dollars is equal to %0.3f GBP (British Pounds)' %(Dollars,GBP))
##################################################################
def main():
print("Hello this program will allow you to make conversions!")
print("You will be able to convert Miles, Temperature, Gallons,")
print("pounds, inches and US Dollars as well!")
ml,km = mile()
fd, cel = fahrenheit()
ga, lit = gallons()
lb, kg = pounds()
ic, cm = inches ()
da, gbp = dollars()
dis = display(ml,km,fd,cel,ga,lit,lb,kg,ic,cm,da,gbp)
main()
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.