-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathf2c.py
More file actions
27 lines (20 loc) · 656 Bytes
/
f2c.py
File metadata and controls
27 lines (20 loc) · 656 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
#!/usr/bin/python3
import sys
# Celsius To Fahrenheit and Fahrenheit to Celsius conversion formulas
#
# Celsius = (Fahrenheit – 32) * 5/9
# Fahrenheit = (Celsius * 9/5) + 32
def f2c(f_value):
fahrenheit = float(f_value)
celsius = (fahrenheit - 32) * 5/9
return celsius
def main(num_args: int, usage: str):
if len(sys.argv) != num_args:
this_script = sys.argv[0]
usage_message = usage.replace("script_name", str(this_script))
print(usage_message)
sys.exit(1)
else:
print(f"{f2c(sys.argv[1]):.2f}")
if __name__ == '__main__':
main(2, 'USAGE: python3 script_name <temp_in_fahrenheit>')