Flask Programs
Flask Programs
app = Flask(__name__)
@app.route('/')
def home():
return render_template('index.html')
@app.route('/calculate', methods=['POST'])
def calculate():
operation = request.form.get('operation')
if operation == 'add':
else:
if __name__ == '__main__':
app.run(debug=False)
index.html
<!DOCTYPE html>
<html>
<head>
<title>Calculator</title>
</head>
<body>
<h2>Simple Calculator</h2>
<option value="add">+</option>
<option value="subtract">−</option>
<option value="multiply">×</option>
<option value="divide">÷</option>
</select>
<button type="submit">=</button>
</form>
</body>
</html>
Grades.py
app = Flask(__name__)
@app.route("/")
def index():
return render_template("index.html")
@app.route("/calculate", methods=["POST"])
def calculate():
average = sum(marks) / 5
grade = "A"
grade = "B"
grade = "C"
else:
grade = "F"
if __name__ == "__main__":
app.run(debug=True)
index.html
<!DOCTYPE html>
<html>
<head>
<title>Student Grades</title>
</head>
<body>
{% for i in range(1, 6) %}
{% endfor %}
<button type="submit">Submit</button>
</form>
{% if grade %}
{% elif error %}
{% endif %}
</body>
</html>