forked from Pabloski001/template-python
-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
31 lines (24 loc) · 975 Bytes
/
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
from flask import Flask, request, render_template
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def calculator():
if request.method == 'POST':
try:
num1 = float(request.form['num1'])
num2 = float(request.form['num2'])
operator = request.form['operator']
if operator == 'add':
result = num1 + num2
elif operator == 'subtract':
result = num1 - num2
elif operator == 'multiply':
result = num1 * num2
elif operator == 'divide':
result = num1 / num2
return render_template('index.html', result=result)
except ValueError:
error_message = 'Por favor ingresa números válidos.'
return render_template('index.html', error=error_message)
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True)