OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

I have a problem in making the conversion of the temperature unit and its [closed]

  • Thread starter Thread starter Mohammad Parsa Mortazavi
  • Start date Start date
M

Mohammad Parsa Mortazavi

Guest
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??

Code:
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.
<p>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??</p>
<pre><code>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!'`
</code></pre>
<p>The problem is from k to f and f to k.</p>
 

Latest posts

D
Replies
0
Views
1
Dhanushka Amarakoon
D
S
Replies
0
Views
1
Shikhar Ambashta
S
Top