Skip to content

Commit 8c49de3

Browse files
Refactor for more descriptive variable naming
Co-authored-by: Bartosz Zaczyński <[email protected]>
1 parent aa6c225 commit 8c49de3

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

python-web-applications/main.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,30 @@
44
app = Flask(__name__)
55

66

7-
def convert_temp(cel_temp):
8-
"""Converts Celsius temperature to Fahrenheit temperature."""
7+
def fahrenheit_from(celsius):
8+
"""Convert Celsius to Fahrenheit degrees."""
99
try:
10-
far_temp = float(cel_temp) * 9 / 5 + 32
11-
far_temp = round(far_temp, 3) # Round to three decimal places
12-
return str(far_temp)
13-
except ValueError: # User entered non-numeric temperature
10+
fahrenheit = float(celsius) * 9 / 5 + 32
11+
fahrenheit = round(fahrenheit, 3) # Round to three decimal places
12+
return str(fahrenheit)
13+
except ValueError:
1414
return "invalid input"
1515

1616

1717
@app.route("/")
1818
def index():
19-
cel_temp = request.args.get("cel_temp")
20-
if cel_temp:
21-
far_temp = convert_temp(cel_temp)
19+
celsius = request.args.get("celsius", "")
20+
if celsius:
21+
fahrenheit = fahrenheit_from(celsius)
2222
else:
23-
far_temp = ""
23+
fahrenheit = ""
2424
return (
25-
"""<form action="">
26-
Celsius: <input type="text" name="cel_temp">
27-
<input type="submit" value="Convert">
25+
"""<form action="" method="get">
26+
Celsius temperature: <input type="text" name="celsius">
27+
<input type="submit" value="Convert to Fahrenheit">
2828
</form>"""
2929
+ "Fahrenheit: "
30-
+ far_temp
30+
+ fahrenheit
3131
)
3232

3333

0 commit comments

Comments
 (0)