create a flask app that multiplies two numbers in python

To create a Flask app that multiplies two numbers, follow these steps:

  1. Install Flask using pip install Flask command in your command prompt or terminal.

  2. Create a new file app.py in your directory and add the following code:

main.py
from flask import Flask, request

app = Flask(__name__)

@app.route('/multiply')
def multiply():
    num1 = int(request.args.get('num1')) # Get first number from query parameters
    num2 = int(request.args.get('num2')) # Get second number from query parameters
    result = num1 * num2 # Multiply the two numbers
    return str(result) # Return the result as a string

if __name__ == '__main__':
    app.run()
411 chars
14 lines
  1. Run the app.py file using the command python app.py in your command prompt or terminal.

  2. Open your browser and go to http://localhost:5000/multiply?num1=5&num2=10 (or any other numbers you want to multiply). You should see 50 as the result on the screen.

That's it! You have successfully created a Flask app that multiplies two numbers.

gistlibby LogSnag