8000 Update challenge · 2cans/python-basics-exercises@24d8e5e · GitHub
[go: up one dir, main page]

Skip to content

Commit 24d8e5e

Browse files
committed
Update challenge
1 parent 806f099 commit 24d8e5e

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

ch06-functions-and-loops/2-challenge.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,23 @@
22
# Solution to challenge
33

44

5-
# Convert Celsius and Fahrenheit temperatures using functions
5+
def convert_cel_to_far(temp_cel):
6+
"""Return the Celsius temperature temp_cel converted to Fahrenheit."""
7+
temp_far = temp_cel * (9 / 5) + 32
8+
return temp_far
69

710

8-
def convert_cel_to_far(cel_temp):
9-
far_temp = cel_temp * 9 / 5 + 32
10-
return far_temp
11+
def convert_far_to_cel(temp_far):
12+
"""Return the Fahrenheit temperature temp_far converted to Celsius."""
13+
temp_cel = (temp_far - 32) * (5 / 9)
14+
return temp_cel
1115

1216

13-
def convert_far_to_cel(far_temp):
14-
cel_temp = (far_temp - 32) * 5 / 9
15-
return cel_temp
17+
temp_far = input("Enter a temperature in degrees F: ")
18+
temp_cel = convert_far_to_cel(float(temp_far))
19+
print(f"{temp_far} degrees F = {temp_cel:.2f} degrees C")
1620

1721

18-
temp1 = 72
19-
print(f"{temp1} degrees F = {convert_far_to_cel(temp1)} degrees C")
20-
21-
temp2 = 37
22-
print(f"{temp2} degrees C = {convert_cel_to_far(temp2)} degrees F")
22+
temp_cel = input("\nEnter a temperature in degrees C: ")
23+
temp_far = convert_cel_to_far(float(temp_cel))
24+
print(f"{temp_cel} degrees C = {temp_far:.2f} degrees F")

0 commit comments

Comments
 (0)
0