Skip to content

Commit e8ee42d

Browse files
committed
addressed the changes made on github
1 parent 9fdf6ad commit e8ee42d

File tree

2 files changed

+9
-20
lines changed

2 files changed

+9
-20
lines changed

conversions/celsius_to_fahrenheit.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
""" Convert temperature from Celsius to Fahrenheit """
22

33

4-
def celsius_to_fahrenheit(celsius):
4+
def celsius_to_fahrenheit(celsius: float) -> float:
55
"""
6-
Convert a given value from Celsius to Fahrenheit
6+
Convert a given value from Celsius to Fahrenheit and round it to 2 decimal places.
77
88
>>> print(celsius_to_fahrenheit(-40))
99
-40.0
@@ -15,20 +15,14 @@ def celsius_to_fahrenheit(celsius):
1515
68.0
1616
>>> print(celsius_to_fahrenheit(40))
1717
104.0
18-
>>> print(celsius_to_fahrenheit("40"))
18+
>>> print(celsius_to_fahrenheit("celsius"))
1919
Traceback (most recent call last):
2020
...
21-
TypeError: 'str' object cannot be interpreted as integer
21+
ValueError: could not convert string to float: 'celsius'
2222
"""
2323

24-
if type(celsius) == str:
25-
"""
26-
Check whether given value is string and raise Type Error
27-
"""
28-
raise TypeError("'str' object cannot be interpreted as integer")
29-
30-
fahrenheit = (celsius * 9 / 5) + 32 # value converted from celsius to fahrenheit
31-
return fahrenheit
24+
celsius = float(celsius)
25+
return round((celsius * 9 / 5) + 32, 2)
3226

3327

3428
if __name__ == "__main__":

conversions/fahrenheit_to_celsius.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,12 @@ def fahrenheit_to_celsius(fahrenheit: float) -> float:
1717
26.67
1818
>>> print(fahrenheit_to_celsius(100))
1919
37.78
20-
>>> print(fahrenheit_to_celsius("100"))
20+
>>> print(fahrenheit_to_celsius("fahrenheit"))
2121
Traceback (most recent call last):
2222
...
23-
TypeError: 'str' object cannot be interpreted as integer
23+
ValueError: could not convert string to float: 'fahrenheit'
2424
"""
25-
if type(fahrenheit) == str:
26-
"""
27-
Check whether given value is string and raise Type Error
28-
"""
29-
raise TypeError("'str' object cannot be interpreted as integer")
30-
25+
fahrenheit = float(fahrenheit)
3126
return round((fahrenheit - 32) * 5 / 9, 2)
3227

3328

0 commit comments

Comments
 (0)