-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
137 lines (107 loc) · 4.16 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#Author:-ENIAC
#Project Name:-ENIAC:Calculator cum Converter
#Team Member:- Shubhanshu Agrawal github:-Shubhanshu1902
# :- Sheersh Jindal github:-SheershJindal
# :- Kshitiz Agrawal github:-Kshitiz1403
from flask import Flask,render_template,request
app=Flask(__name__)
@app.route("/")
def app1():
return render_template("index.html")
@app.route("/calc")#,methods=['POST'])
def calc():
return render_template("calc.html")
@app.route("/sendCalc", methods=['POST'])
def calculate():
num1 = request.form['num1']
num2 = request.form['num2']
operation = request.form['operation']
num1 = num1.strip()
num1 = ''.join(i for i in num1 if i.isdigit())
num2 = num2.strip()
num2 = ''.join(i for i in num2 if i.isdigit())
if num1 == '' or num2 == '':
return render_template('calc.html')
elif operation=="add":
result=float(num1)+float(num2)
return render_template('calc.html',result=result)
elif operation=="subtract":
result=float(num1)-float(num2)
return render_template('calc.html',result=result)
elif operation=="multiply":
result=float(num1)*float(num2)
return render_template('calc.html',result=result)
elif operation=="divide":
result=float(num1)/float(num2)
return render_template('calc.html',result=result)
else:
return render_template("calc.html")
@app.route("/binary")
def binary():
return render_template("binary.html")
@app.route("/sendBinary",methods=['POST'])
def converter():
num = request.form['num']
inputOperation = request.form['input-operation']
outputOperation = request.form['output-operation']
num = num.strip()
num = ''.join(i for i in num if i.isdigit())
if num == '':
return render_template('binary.html')
elif inputOperation == "Binary":
if outputOperation=="Decimal":
result=int(num,2)
return render_template('binary.html',result=result)
elif outputOperation=="Hexadecimal":
result=int(num,2)
result=hex(result)
return render_template('binary.html',result=result)
elif outputOperation=="Octal":
result=int(num,2)
result=oct(result)
return render_template('binary.html',result=result)
else:
return render_template('binary.html')
elif inputOperation == "Decimal":
num=int(num)
if outputOperation=="Binary":
result=bin(num)
return render_template('binary.html',result=result)
elif outputOperation=="Hexadecimal":
result=hex(num)
return render_template('binary.html',result=result)
elif outputOperation=="Octal":
result=oct(num)
return render_template('binary.html',result=result)
else:
return render_template('binary.html')
elif inputOperation == "Hexadecimal":
num=int(num,16)
if outputOperation=="Binary":
result=bin(num)
return render_template('binary.html',result=result)
elif outputOperation=="Decimal":
result=num
return render_template('binary.html',result=result)
elif outputOperation=="Octal":
result=oct(num)
return render_template('binary.html',result=result)
else:
return render_template('binary.html')
elif inputOperation == "Octal":
num=int(num,8)
if outputOperation=="Binary":
result=bin(num)
return render_template('binary.html',result=result)
elif outputOperation=="Decimal":
result=num
return render_template('binary.html',result=result)
elif outputOperation=="Hexadecimal":
result=hex(num)
return render_template('binary.html',result=result)
else:
return render_template('binary.html')
else:
return render_template("binary.html")
if __name__ == "__main__":
app.run(debug=True)