-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample1.py
More file actions
30 lines (22 loc) · 724 Bytes
/
Copy pathexample1.py
File metadata and controls
30 lines (22 loc) · 724 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
# Example 1
def main():
fahr_temps = [72, 65, 71, 75, 82, 87, 68]
# Print the Fahrenheit temperatures.
print(f"Fahrenheit: {fahr_temps}")
# Convert each Fahrenheit temperature to Celsius and store
# the Celsius temperatures in a list named cels_temps.
cels_temps = []
for fahr in fahr_temps:
cels = cels_from_fahr(fahr)
cels_temps.append(cels)
# Print the Celsius temperatures.
print(f"Celsius: {cels_temps}")
def cels_from_fahr(fahr):
"""Convert a Fahrenheit temperature to
Celsius and return the Celsius temperature.
"""
cels = (fahr - 32) * 5 / 9
return round(cels, 1)
# Call main to start this program.
if __name__ == "__main__":
main()