Advertisement
Guest User

Untitled

a guest
Jul 18th, 2021
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. allowed_types = ["F", "C", "K"]
  2. temp_type = input("Which type of temperature (F, C, or K): ").upper()
  3. if temp_type not in allowed_types:
  4. print("Invalid code.")
  5. else:
  6. temp = int(input("Enter temperature: "))
  7. if temp < -500 or temp > 500:
  8. print("INVALID value for temperature – setting temperature value to 100")
  9. temp = 100
  10.  
  11. if temp_type == "F":
  12. F = temp
  13. C = (F - 32) * 5/9
  14. K = (F + 459.67) * 5/9
  15. elif temp_type == "C":
  16. C = temp
  17. F = C * 9/5 + 32
  18. K = (9/5 * C + 491.67) * 5/9
  19. else:
  20. K = temp
  21. F = 9/5 * K - 459.67
  22. C = (9/5 * K - 491.67) * 5/9
  23.  
  24. print("Temperature in degrees Fahrenheit:", F)
  25. print("Temperature in degrees Celsius:", C)
  26. print("Temperature in degrees Kelvin:", K)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement