I just started learning python and am currently writing a script that converts Celsius to Fahrenheit and vise versa. I have the main part done but now I want to be able to let the user set the number of decimals displayed in the output... The first function contains my failed attempt and the second is set at 2 decimal places.
def convert_f_to_c(t,xx):
c = (t - 32) * (5.0 / 9)
print "%.%f" % (c, xx)
def convert_c_to_f(t):
f = 1.8 * t + 32
print "%.2f" % f
print "Number of decimal places?"
dec = raw_input(">")
print "(c) Celsius >>> Ferenheit\n(f) Ferenheit >>> Celcius"
option = raw_input(">")
if option == 'c':
cel = int(raw_input("Temperature in Celcius?"))
convert_c_to_f(cel)
else:
fer = int(raw_input("Temperature in Ferenheit?"))
convert_f_to_c(fer,dec)