Write a Python program to convert temperatures to and from celsius, fahrenheit


Introduction

Write a Python program to convert temperatures to and from celsius, fahrenheit. I have used python 3.7 compiler for debugging purpose.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. temp = input("Input the temperature you like to convert? (e.g., 25F, 90C etc.) : ")
  2. degree = int(temp[:-1])
  3. i_convention = temp[-1]
  4.  
  5. if i_convention.upper() == "C":
  6. result = int(round((9 * degree) / 5 + 32))
  7. o_convention = "Fahrenheit"
  8. elif i_convention.upper() == "F":
  9. result = int(round((degree - 32) * 5 / 9))
  10. o_convention = "Celsius"
  11. else:
  12. print("Input proper convention.")
  13. quit()
  14. print("The temperature in", o_convention, "is", result, "degrees.")

Result

python language techstudy.org

     





Related Topics




Popular Posts