diff options
| author | mo khan <mo@mokhan.ca> | 2025-03-12 18:04:48 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-03-12 18:04:48 -0600 |
| commit | 4afccc51c225b872d1665c6e07983f92e4b7aa13 (patch) | |
| tree | fe1e4d3e3bbf3ff0cad0d708873c1588080a6f76 | |
| parent | e8e6fb49665c0dba2ab0703b5e25ed8a5e08faf8 (diff) | |
Use the builtin round function with 1 decimal place
| -rw-r--r-- | f-to-c.py | 10 |
1 files changed, 1 insertions, 9 deletions
@@ -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)) |
