My calc

The sum of two numbers (Flask)

 
Task: Get the sum of two numbers
Code:
    app.py (or similar)

    from flask import Flask, render_template, request

    app = Flask(__name__)
    ….
    @app.route('/plus', methods=['GET', 'POST'])
    def plus():
        result = None
        if request.method == 'POST':
            try:
                num1 = float(request.form.get('num1', 0))
                num2 = float(request.form.get('num2', 0))
                result = num1 + num2
            except ValueError:
                result = "Error: Enter the numbers"
        return render_template('plus.html', result=result)

    if __name__ == '__main__':

2026-08-06 10:46:47

Comments

No comments yet. Be the first to leave one!

Leave a Comment