File tree Expand file tree Collapse file tree 3 files changed +37
-0
lines changed
Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ runtime : python38
Original file line number Diff line number Diff line change 1+ from flask import Flask
2+ from flask import request
3+
4+ app = Flask (__name__ )
5+
6+
7+ def fahrenheit_from (celsius ):
8+ """Convert Celsius to Fahrenheit degrees."""
9+ try :
10+ fahrenheit = float (celsius ) * 9 / 5 + 32
11+ fahrenheit = round (fahrenheit , 3 ) # Round to three decimal places
12+ return str (fahrenheit )
13+ except ValueError :
14+ return "invalid input"
15+
16+
17+ @app .route ("/" )
18+ def index ():
19+ celsius = request .args .get ("celsius" , "" )
20+ if celsius :
21+ fahrenheit = fahrenheit_from (celsius )
22+ else :
23+ fahrenheit = ""
24+ return (
25+ """<form action="" method="get">
26+ Celsius temperature: <input type="text" name="celsius">
27+ <input type="submit" value="Convert to Fahrenheit">
28+ </form>"""
29+ + "Fahrenheit: "
30+ + fahrenheit
31+ )
32+
33+
34+ if __name__ == "__main__" :
35+ app .run (host = "127.0.0.1" , port = 8080 , debug = True )
Original file line number Diff line number Diff line change 1+ Flask == 1.1.2
You can’t perform that action at this time.
0 commit comments