From 4f423db64ac672abb1d5fdc4cb3622cd1b905d9a Mon Sep 17 00:00:00 2001 From: ongsici Date: Mon, 28 Oct 2024 15:09:49 +0000 Subject: [PATCH] feat: sq and cube --- src/app.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/app.py b/src/app.py index d326794..0f291e0 100644 --- a/src/app.py +++ b/src/app.py @@ -1,8 +1,25 @@ from flask import Flask, render_template, request app = Flask(__name__) +import math + +def is_square(n): + return int(math.sqrt(n)) ** 2 == n + +def is_cube(n): + return int(round(n ** (1/3))) ** 3 == n def process_query(input): + if "square and a cube" in input: + input = input.replace("?", "") + value = input.split(":")[-1].split(",") + result = [] + for number in value: + number=number.strip() + if is_square(int(number)) and is_cube(int(number)): + result.append(number) + return ", ".join(result) + if "plus" in input: new_input = input.replace("?", "") value1 = int(new_input.split(" ")[2])