File tree 1 file changed +10
-9
lines changed
1 file changed +10
-9
lines changed Original file line number Diff line number Diff line change 1
1
from flask import Flask , render_template , request
2
2
3
- # declare the app
3
+ # Declare the app
4
4
app = Flask (__name__ )
5
5
6
- # start an app route
6
+ # Start an app route
7
7
@app .route ("/" )
8
8
def main ():
9
9
return render_template ("index.html" )
10
10
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" ])
14
13
def calculate ():
15
14
try :
16
15
w = float (request .form .get ("weight" ))
17
16
h = float (request .form .get ("height" ))
18
- if w and h :
17
+ if w > 0 and h > 0 :
19
18
bmi = round (w / ((h / 100 ) ** 2 ), 3 )
20
19
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."
23
25
return render_template ("index.html" , error = error )
24
26
25
-
26
27
if __name__ == "__main__" :
27
28
app .run (debug = True )
You can’t perform that action at this time.
0 commit comments