I have made a simple calculator.py program, but the program fails with "NameError: "a" is not defined".
My program supports simple operations such as addition, subtraction, multiplication and division, as well as more complex operations like modulo and power.
I have included my code below. How can I fix it?
import mathdef control(a, x, y, z, k): return {'ADDITION': addition(x, y),'SUBTRACTION': subtraction(x, y),'MULTIPLICATION': multiplication(x, y),'DIVISION': division(x, y),'MOD': modulo(x, y),'SECONDPOWER': secondPower(x),'POWER': power(x, y),'SECONDRADIX': secondRadix(x),'MAGIC': magic(x, y, z, k) }[a]def addition(x, y): return float(x) + float(y)def subtraction(x, y): return float(x) - float(y)def multiplication(x, y): return float(x) * float(y)def division(x, y): return float(x) / float(y)def modulo(x, y): return float(x) % float(y)def secondPower(x): return math.pow(float(x), 2.0)def power(x, y): return math.pow(float(x), float(y))def secondRadix(x): return math.sqrt(float(x))def magic(x, y, z, k): l = float(x) + float(k) m = float(y) + float(z) return (l / m) + 1.0try: control(a, x, y, z, k)except ValueError: print("This operation is not supported for given input parameters")out = control(a, x, y, z, k)print(out)The trackback for my error is as follows:
Traceback (most recent call last): control(a, x, y, z, k)NameError: name 'a' is not defined