File tree Expand file tree Collapse file tree 1 file changed +10
-9
lines changed Expand file tree Collapse file tree 1 file changed +10
-9
lines changed Original file line number Diff line number Diff line change 11from flask import Flask , render_template , request
22
3- # declare the app
3+ # Declare the app
44app = Flask (__name__ )
55
6- # start an app route
6+ # Start an app route
77@app .route ("/" )
88def main ():
99 return render_template ("index.html" )
1010
11-
12- # route for bmi calculation result
13- @app .route ("/bmi" , methods = ["GET" , "POST" ])
11+ # Route for BMI calculation result
12+ @app .route ("/bmi" , methods = ["POST" ])
1413def calculate ():
1514 try :
1615 w = float (request .form .get ("weight" ))
1716 h = float (request .form .get ("height" ))
18- if w and h :
17+ if w > 0 and h > 0 :
1918 bmi = round (w / ((h / 100 ) ** 2 ), 3 )
2019 return render_template ("index.html" , bmi = bmi )
21- except ValueError as error :
22- error = "Please enter all the values"
20+ else :
21+ error = "Weight and height must be positive numbers."
22+ return render_template ("index.html" , error = error )
23+ except ValueError :
24+ error = "Please enter valid numeric values."
2325 return render_template ("index.html" , error = error )
2426
25-
2627if __name__ == "__main__" :
2728 app .run (debug = True )
You can’t perform that action at this time.
0 commit comments