File tree Expand file tree Collapse file tree 1 file changed +14
-14
lines changed
Expand file tree Collapse file tree 1 file changed +14
-14
lines changed Original file line number Diff line number Diff line change 44app = 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 ("/" )
1818def 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
You can’t perform that action at this time.
0 commit comments