diff --git a/app.py b/app.py index 59f82a4..6cdad99 100644 --- a/app.py +++ b/app.py @@ -1,50 +1,43 @@ -# Change and configure your own app ! -from flask import Flask, jsonify, request +from flask import Flask, jsonify, request, render_template_string +import random app = Flask(__name__) -# In-memory storage for expenses -expenses = [] - - -@app.route("/") +# HTML template for the web interface +HTML_TEMPLATE = """ + + + + Random Number Generator + + +

Random Number Generator

+

Generate a Random Number

+
+ +

+ +

+ +
+ + +""" + +@app.route('/') def home(): - return "Welcome to the Personal Expense Tracker!" - - -# Add a new expense -@app.route("/expenses", methods=["POST"]) -def add_expense(): - data = request.json - if "description" not in data or "amount" not in data or "date" not in data: - return ( - jsonify({"error": "Expense must have a description, amount, and date"}), - 400, - ) - - expense = { - "id": len(expenses) + 1, - "description": data["description"], - "amount": data["amount"], - "date": data["date"], - } - expenses.append(expense) - return jsonify(expense), 201 - - -# Get all expenses -@app.route("/expenses", methods=["GET"]) -def get_expenses(): - return jsonify(expenses) - - -# Delete an expense by ID -@app.route("/expenses/", methods=["DELETE"]) -def delete_expense(expense_id): - global expenses - expenses = [expense for expense in expenses if expense["id"] != expense_id] - return jsonify({"message": "Expense deleted"}), 200 - - -if __name__ == "__main__": + return HTML_TEMPLATE + +@app.route('/generate', methods=['POST']) +def generate_number(): + min_value = int(request.form.get('min', 1)) + max_value = int(request.form.get('max', 100)) + + if min_value >= max_value: + return "Invalid range! Min must be less than Max.", 400 + + number = random.randint(min_value, max_value) + return f"

Generated Random Number: {number}

" + +if __name__ == '__main__': app.run(debug=True)