I am building a temperature conversion module called Unico. Now, when I want to convert kelvin to fahrenheit or fahrenheit to kelvin, it makes a calculation error. Of course, there is no problem when the input number is non-decimal.
What’s the problem??
preunit,nextunit = prenext.split(' ')
prenum = int(prenum)
if preunit == 'c' and prenum>=(-273.15):
if nextunit == 'k':
return round(prenum + 273.15,2)
if nextunit == 'f':
return round(prenum * 1.8 + 32,2)
elif preunit == 'k' and prenum>=0:
if nextunit == 'c':
return round(prenum - 273.15,2)
if nextunit == 'f':
if prenum == 0:
return -459.67
return round(((prenum-273.15)*1.8)+32,2)
elif preunit == 'f' and prenum>=-459.67:
if nextunit == 'c':
return round((prenum - 32)/1.8,2)
if nextunit == 'k':
return round(((prenum - 32)/1.8)+273.15,2)
else:
return 'Unit Not Found!'`
The problem is from k to f and f to k.
New contributor
Mohammad Parsa Mortazavi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.