summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-03-12 18:04:48 -0600
committermo khan <mo@mokhan.ca>2025-03-12 18:04:48 -0600
commit4afccc51c225b872d1665c6e07983f92e4b7aa13 (patch)
treefe1e4d3e3bbf3ff0cad0d708873c1588080a6f76
parente8e6fb49665c0dba2ab0703b5e25ed8a5e08faf8 (diff)
Use the builtin round function with 1 decimal place
-rw-r--r--f-to-c.py10
1 files changed, 1 insertions, 9 deletions
diff --git a/f-to-c.py b/f-to-c.py
index 3495f48..f96895b 100644
--- a/f-to-c.py
+++ b/f-to-c.py
@@ -4,18 +4,10 @@ def assert_equal(expected, actual):
if expected != actual:
raise Exception("expected: {}, actual: {}".format(expected, actual))
-def round(number):
- x = number % 1.0
- y = int(number % 10.0)
- if y > 5:
- return (number - x) + float((y / 10.0) + (0.1))
- else:
- return (number - x) + float((y / 10.0))
-
def f_to_c(fahrenheit):
fahrenheit_float = float(fahrenheit)
celsius_converted = ((fahrenheit_float - 32.0) * 5.0 / 9.0)
- return round(celsius_converted)
+ return round(celsius_converted, 1)
fahrenheit = input("What is the temperature in Fahrenheit? ")
assert_equal(37.8, f_to_c(100))