forked from mvasam/FinalPercentage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
122 lines (109 loc) · 3.31 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
from flask import Flask, request, render_template
app = Flask(__name__,static_url_path='/static')
def exceptionalZ(x,y):
r=0
try:
r=x/y
except ZeroDivisionError:
return 0
return x/y
def Percentage(marksObtained,totalMarks):
per=0
try:
per=marksObtained/totalMarks
except ZeroDivisionError:
return 0
return (marksObtained/totalMarks)*100
def exceptionalH(value):
try:
float(value)
return float(value)
except:
print("Input must be a valid number. Non-special characters, commas and spaces are not accepted.")
return -1
@app.route("/",methods=['GET','POST'])
def hello_world():
error_message=''
per=0
fsobtained=0
fstotal=0
tsobtained=0
tstotal=0
if request.method=='POST':
if 'm1' in request.form:
m1=request.form.get('m1')
m1=exceptionalH(m1)
if 't1' in request.form:
t1=request.form.get('t1')
t1=exceptionalH(t1)
if(t1>0):
fsobtained+=m1
fstotal+=t1
if 'm2' in request.form:
per=0
m2=request.form.get('m2')
m2=exceptionalH(m2)
if 't2' in request.form:
t2=request.form.get('t2')
t2=exceptionalH(t2)
if(t2>0):
fsobtained+=m2
fstotal+=t2
if 'm3' in request.form:
per=0
m3=request.form.get('m3')
m3=exceptionalH(m3)
if 't3' in request.form:
t3=request.form.get('t3')
t3=exceptionalH(t3)
if(t3>0):
fsobtained+=m3
fstotal+=t3
if 'm4' in request.form:
per=0
m4=request.form.get('m4')
m4=exceptionalH(m4)
if 't4' in request.form:
t4=request.form.get('t4')
t4=exceptionalH(t4)
if(t4>0):
tsobtained+=m4
tstotal+=t4
if 'm5' in request.form:
per=0
m5=request.form.get('m5')
m5=exceptionalH(m5)
if 't5' in request.form:
t5=request.form.get('t5')
t5=exceptionalH(t5)
if(t5>0):
tsobtained+=m5
tstotal+=t5
if 'm6' in request.form:
per=0
m6=request.form.get('m6')
m6=exceptionalH(m6)
if 't6' in request.form:
t6=request.form.get('t6')
t6=exceptionalH(t6)
if(t6>0):
tsobtained+=m6
tstotal+=t6
if 'm7' in request.form:
per=0
m7=request.form.get('m7')
m7=exceptionalH(m7)
if 't7' in request.form:
t7=request.form.get('t7')
t7=exceptionalH(t7)
if(t7>0):
tsobtained+=m7
tstotal+=t7
fsobtained=fsobtained/2
fstotal=fstotal/2
obtained=fsobtained+tsobtained
total=fstotal+tstotal
final=Percentage(obtained,total)
return render_template("index.html",final=final)
if __name__=='__main__':
app.run(debug=True)