File tree Expand file tree Collapse file tree 5 files changed +46
-31
lines changed Expand file tree Collapse file tree 5 files changed +46
-31
lines changed Original file line number Diff line number Diff line change 1
1
from flask import Flask , render_template , request
2
+ from handle_calculation import calculate
2
3
3
4
app = Flask (__name__ )
4
5
app .config .from_object (__name__ )
8
9
def welcome ():
9
10
return render_template ('form.html' )
10
11
11
-
12
12
@app .route ('/result' , methods = ['POST' ])
13
13
def result ():
14
14
operand_1 = request .form .get ("operand_1" , type = int )
15
15
operand_2 = request .form .get ("operand_2" , type = int )
16
16
operator = request .form .get ("operator" )
17
- if (operand_2 == 0 and operator == 'Division' ):
18
- result = 'Invalid_operation'
19
- elif (operator == 'Addition' ):
20
- result = operand_1 + operand_2
21
- elif (operator == 'Subtraction' ):
22
- result = operand_1 - operand_2
23
- elif (operator == 'Multiplication' ):
24
- result = operand_1 * operand_2
25
- elif (operator == 'Division' ):
26
- result = operand_1 / operand_2
27
- else :
28
- result = 'Invalid_Choice'
17
+ result = calculate (operand_1 , operand_2 , operator )
29
18
entry = result
30
19
return render_template ('result.html' , entry = entry )
31
20
Original file line number Diff line number Diff line change
1
+ # handle_calculation.py
2
+
3
+ def calculate (operand_1 : int , operand_2 : int , operator : str ) -> int :
4
+ """
5
+ calculation between the operands using the operator and returns a value
6
+
7
+ Parameters:
8
+
9
+ -operand_1: the first given value
10
+ -operand_2: the second given value
11
+ -operator: used to trigger the calculation
12
+ """
13
+ if (operand_2 == 0 and operator == 'Division' ):
14
+ result = 'Invalid_operation'
15
+ elif (operator == 'Addition' ):
16
+ result = operand_1 + operand_2
17
+ elif (operator == 'Subtraction' ):
18
+ result = operand_1 - operand_2
19
+ elif (operator == 'Multiplication' ):
20
+ result = operand_1 * operand_2
21
+ elif (operator == 'Division' ):
22
+ result = operand_1 / operand_2
23
+ else :
24
+ result = 'Invalid_Choice'
25
+
26
+ return result
Original file line number Diff line number Diff line change 29
29
</ div >
30
30
</ div >
31
31
< div class ="form-group ">
32
- < label class ="control-label col-xs-3 "> OPERATOR:</ label >
33
- < div class ="col-xs-5 ">
34
- < select class ="form-control " name ="operator ">
35
- < option > Addition</ option >
36
- < option > Subtraction</ option >
37
- < option > Multiplication</ option >
38
- < option > Division</ option >
39
- </ select >
40
- </ div >
41
- </ div >
32
+ < label class ="control-label col-xs-3 "> OPERATOR:</ label >
33
+ < div class ="col-xs-5 ">
34
+ < select class ="form-control " name ="operator ">
35
+ < option > Addition</ option >
36
+ < option > Subtraction</ option >
37
+ < option > Multiplication</ option >
38
+ < option > Division</ option >
39
+ </ select >
40
+ </ div >
41
+ </ div >
42
42
< div class ="form-group ">
43
- < div class ="col-xs-offset-3 col-xs-9 ">
44
- < input type ="submit " class ="btn btn-success " value ="Submit ">
45
- < input type ="reset " class ="btn btn-danger " value ="Reset ">
46
- </ div >
47
- </ div >
48
- </ form >
49
- </ div >
50
- < div class ="col-md-4 "> </ div > </ div >
43
+ < div class ="col-xs-offset-3 col-xs-9 ">
44
+ < input type ="submit " class ="btn btn-success " value ="Submit ">
45
+ < input type ="reset " class ="btn btn-danger " value ="Reset ">
46
+ </ div >
47
+ </ div >
48
+ </ form >
49
+ </ div >
50
+ < div class ="col-md-4 "> </ div > </ div >
51
51
</ div >
52
52
</ body >
53
53
</ html >
You can’t perform that action at this time.
0 commit comments