I’m working on a Python script where I have two variables containing numbers, these being the variables number_x and number_y respectively. Additionally, I have a third variable, operation_a, which holds a string representing a mathematical operation like ‘addition’, ‘subtraction’, ‘multiplication’, or ‘division’.
What I want to achieve is to dynamically convert the operation variable into the actual mathematical operation so that I can perform calculations using num1 and num2 as operands. How can I achieve this in Python?
I haven’t tried anything yet, mainly just thinking as to how exactly I’d go about making it, but so far, nothing yet.
Kitsune is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.