summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-03-12 17:38:00 -0600
committermo khan <mo@mokhan.ca>2025-03-12 17:38:00 -0600
commite8e6fb49665c0dba2ab0703b5e25ed8a5e08faf8 (patch)
treefe2fb458b2601ea29e2eb89bba827514b4d7ee26
parentc39996edcd318ec6a8b7e4274d28a8253be28c34 (diff)
Add fahrenheit to celsius
-rw-r--r--f-to-c.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/f-to-c.py b/f-to-c.py
new file mode 100644
index 0000000..3495f48
--- /dev/null
+++ b/f-to-c.py
@@ -0,0 +1,23 @@
+#!/usr/bin/env python
+
+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)
+
+fahrenheit = input("What is the temperature in Fahrenheit? ")
+assert_equal(37.8, f_to_c(100))
+
+print("The temperature in Celsius is", f_to_c(fahrenheit))