-
Notifications
You must be signed in to change notification settings - Fork 367
Expand file tree
/
Copy pathpep8_sample.py
More file actions
33 lines (24 loc) · 854 Bytes
/
Copy pathpep8_sample.py
File metadata and controls
33 lines (24 loc) · 854 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
"""This script shows a few PEP 8 rules."""
import datetime as dt
TEMPERATURE_SCALES = (
"fahrenheit",
"kelvin",
"celsius",
)
class TemperatureConverter:
pass # Doesn't do anything at the moment
def convert_to_celsius(degrees, source="fahrenheit"):
"""This function converts degrees Fahrenheit or Kelvin
into degrees Celsius.
"""
if source.lower() == "fahrenheit":
return (degrees - 32) * (5 / 9)
elif source.lower() == "kelvin":
return degrees - 273.15
else:
# Exceptions will be introduced in Chapter 10
raise ValueError(f"Don't know how to convert from {source}")
celsius = convert_to_celsius(44, source="fahrenheit")
non_celsius_scales = TEMPERATURE_SCALES[:-1]
print("Current time: " + dt.datetime.now().isoformat())
print(f"The temperature in Celsius is: {celsius}")