Using the following python program make changes to do the following: 1. Create a
ID: 3689201 • Letter: U
Question
Using the following python program make changes to do the following:
1. Create a table using a two-dimensional list that stores a Fahrenheit temperature and the equivalent Celsius temperature. Use the following range of Fahrenheit temperatures: -10 through 100 in increments of 10. Thus the temperatures will be:
-10, 0, 10, 20, 30, 40, 50…and so on.
2. Display the contents of the list.
3. Similarly create tables/lists for:
a. Miles to kilometers
b. Gallons to liters
c. Pounds to kilograms
d. Inches to centimeters
e. Dollars to GBP
Display the contents of each list.
##################################################################
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)
print('%0.3f Miles is equal to %0.3f Kilometers' %(miles,kilometers))
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
print('%0.1f degree Fahrenheit is equal to %0.1f degree Celsius' %(fahrenheit,celsius))
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
print('%0.3f Gallons is equal to %0.3f Liters' %(gallons,liters))
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
print('%0.3f Pounds is equal to %0.3f kilograms' %(pounds,kilograms))
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
print('%0.3f Inches is equal to %0.3f Centimeters' %(inches,centimeters))
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
print('%0.3f Dollars is equal to %0.3f GBP (British Pounds)' %(Dollars,GBP))
return (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!")
count = 0
chooseType()
for count in range (3):
count = count + 1
chooseType()
while (count >= 4):
print ("Program will End.")
quit()
##################################################################
def chooseType():
ml=km=fd=cel=ga=lit=lb=kg=ic=cm=da=gbp=0
print("Choose the type of measurement you would like to use.")
print("1. Miles to Kilometers")
print("2. Fahrenheit to Celsius")
print("3. Gallons to Liters")
print("4. Pounds to Kilograms")
print("5. Inches to Centimeters")
print("6. USD Dollars to British GBP")
choice = int(input("Enter a number: "))
if choice == 1:
ml, km = mile()
elif choice == 2:
fd,cel = fahrenheit()
elif choice == 3:
ga,lit = gallons()
elif choice == 4:
lb,kg = pounds()
elif choice == 5:
ic,cm = inches ()
elif choice == 6:
da,gbp = dollars()
else:
print("Not a valid choice.")
chooseType()
##################################################################
main()
Explanation / Answer
def f2c(f):
return (f-32)*5/9
def m2k(m):
return 1.6*m
def g2l(g):
return 3.9*g
def p2k(i):
return 0.45*g
def i2c(i):
return 2.54*i
def d2b(i)
return 0.69*i
f2clist = [[] for i in range(12)]
print f2c(98.4)
x= -10.0
i=0
while(x<=100.0):
f2clist[i]=[x,f2c(x)]
x=x+10.0
i=i+1
m2klist = [[] for i in range(11)]
i=0
x= 0.0
while(x<=100.0):
m2klist[i]=[x,m2k(x)]
x=x+10.0
i=i+1
g2llist = [[] for i in range(11)]
i=0
x= 0.0
while(x<=100.0):
g2llist[i]=[x,g2l(x)]
x=x+10.0
i=i+1
p2klist = [[] for i in range(11)]
i=0
x= 0.0
while(x<=100.0):
p2klist[i]=[x,p2k(x)]
x=x+10.0
i=i+1
i2clist = [[] for i in range(11)]
i=0
x= 0.0
while(x<=100.0):
i2clist[i]=[x,i2c(x)]
x=x+10.0
i=i+1
d2blist = [[] for i in range(11)]
i=0
x= 0.0
while(x<=100.0):
d2blist[i]=[x,d2b(x)]
x=x+10.0
i=i+1
print "Fahrenheit to celsius conversions:"
for i in range(12):
print f2clist[i]
print "miles to kilometers conversions:"
for i in range(11):
print m2klist[i]
print "gallons to litres conversions:"
for i in range(11):
print g2llist[i]
print "pounds to kilograms conversions:"
for i in range(11):
print p2klist[i]
print "inches to centimeters conversions:"
for i in range(11):
print i2clist[i]
print "Dollars to GBP:"
for i in range(11):
print d2blist[i]
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.