@@ -5,8 +5,8 @@ def preprocess(expression):
55 # Replace caret with exponent operator
66 expression = expression .replace ('^' , '**' )
77
8- # Replace square symbols like 5² with 5**2
9- expression = re .sub (r'(\d+)²' , r'(\1**2)' , expression )
8+ # Replace square symbols like 5² with 5**2
9+ expression = re .sub (r'(\d+)²' , r'(\1**2)' , expression )
1010
1111 # Replace sqrt(x) with math.sqrt(x)
1212 expression = re .sub (r'sqrt\(([^)]+)\)' , r'math.sqrt(\1)' , expression )
@@ -15,12 +15,12 @@ def preprocess(expression):
1515
1616def is_safe_expression (expr ):
1717 # Only allow numbers, operators, parentheses, and valid keywords
18- return bool (re .match (r'^[\d\s+\-*/().^sqrt²]+$' , expr ))
18+ return bool (re .match (r'^[\d\s+\-*/().^sqrt²]+$' , expr ))
1919
2020def calculate_advanced (expression ):
2121 expression = expression .replace (' ' , '' ) # Remove spaces
2222 if not is_safe_expression (expression ):
23- return "? Invalid input! Only numbers and basic operators (plus ^, sqrt, ²) are allowed."
23+ return "? Invalid input! Only numbers and basic operators (plus ^, sqrt, ²) are allowed."
2424
2525 try :
2626 safe_expr = preprocess (expression )
@@ -34,4 +34,4 @@ def calculate_advanced(expression):
3434 user_input = input ("Enter expression (or 'exit' to quit): " )
3535 if user_input .lower () == 'exit' :
3636 break
37- print (calculate_advanced (user_input ))
37+ print (calculate_advanced (user_input ))
0 commit comments