-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemperature.py
More file actions
35 lines (26 loc) · 1019 Bytes
/
Copy pathtemperature.py
File metadata and controls
35 lines (26 loc) · 1019 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Given a temperature in Celsius
# degrees,
# write a method that converts it to Fahrenheit degrees or vice versa.
# Remember that temperature below -271.15C (absolute zero) does not exist!
# convert celsius to fahrenheit
def celsius_to_fahrenheit(celsius):
if celsius < -273.15:
return "That temperature does not exist!"
# [(Celsius value) × (9/5)] + 32
fahrenheit = (celsius * (9/5)) + 32
return fahrenheit
# Expected Input and Output:
# test function celcius to fahrenheit
def test_celsius_to_fahrenheit():
print(celsius_to_fahrenheit(-15) == "That temperature does not exist!")
# convert fahrenheit to celsius
def fahrenheit_to_celsius(fahrenheit):
if fahrenheit < -459.67:
return "That temperature does not exist!"
# formular for celsius from fahrenheit
# [(Fahrenheit value) - (32)] * (5/9)
celsius = (fahrenheit - 32) * (5/9)
return celsius
# test function fahrenheit to celsius
# get some reliable data later
print(celsius_to_fahrenheit(-15))