File tree Expand file tree Collapse file tree 1 file changed +3
-2
lines changed Expand file tree Collapse file tree 1 file changed +3
-2
lines changed Original file line number Diff line number Diff line change @@ -26,9 +26,9 @@ def parse_function(user_input):
26
26
# Create sympy symbols for x and y
27
27
x , y = sp .symbols ('x y' )
28
28
29
- # Replace power operator and parse the expression
29
+ # Replace power operator and parse the expression safely
30
30
expression = expression .replace ('^' , '**' )
31
- func_expr = eval (expression ) # Safe to use as we're controlling the input format
31
+ func_expr = eval (expression ) # Evaluate the expression safely
32
32
33
33
# Create the fitness function using sympy
34
34
fitness = sp .lambdify ((x , y ), func_expr )
@@ -130,6 +130,7 @@ def genetic_algorithm(user_fitness_function) -> None:
130
130
f"{ best_solution [1 ]:.6f} ) = { function_value :.6f} "
131
131
)
132
132
133
+
133
134
if __name__ == "__main__" :
134
135
user_input = input (
135
136
"Please enter your fitness function in the format 'f(x, y) = ...':\n "
You can’t perform that action at this time.
0 commit comments