Advertisement
trds

celsiusToFahrenheit / fahrenheitToCelsius

Jan 3rd, 2021
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. # v1
  2. celsius = float(input("Introduceti temperatura celsius:"))
  3. fahrenheit= ((celsius * 9) / 5) + 32
  4. print (fahrenheit)
  5.  
  6. fahrenheit = float(input("Introduceti temperatura fahrenheit"))
  7. celsius= (5/9) * fahrenheit -32
  8. print (celsius)
  9.  
  10. # v2
  11. def citire():
  12.     g = float(input("Introduceti gradele care doriti sa le convertiti:"))
  13.     return g
  14.  
  15. def celsiusToFahrenheit(celsius):
  16.     fahrenheit = (9/5) * celsius * 12
  17.     return fahrenheit
  18.  
  19. def fahrenheitToCelsius(fahrenheit):
  20.     celsius = (5/9) * (fahrenheit - 32)
  21.     return celsius
  22.  
  23. grade = citire()
  24. grade1 = citire()
  25. grade2 = citire()
  26. grade3 = citire()
  27. print("{} {:>20} {:>5} {:>15} {:>20}".format("Celsius", "Fahrenheit" ,"|", "Fahrenheit", "Celsius"))
  28. print("{:.2f} {:>20} {:>7} {:>13} {:>20.2f}".format(grade,celsiusToFahrenheit(grade), "|", grade2, fahrenheitToCelsius(grade2)))
  29. print("{:.2f} {:>20} {:>7} {:>13} {:>20.2f}".format(grade1,celsiusToFahrenheit(grade1), "|", grade3, fahrenheitToCelsius(grade3)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement