When I testing division with x = 5 , y = 32 so, division function does not working.
This is impossible: '1/0' , in that I added 'try & except' after it 'return float(x) / float(y)' not working.
import math
def 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)
}
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):
if(y != 0):
return float(x) / float(y)
else:
raise
return ValueError("This operation is not supported for given input parameters")
if (x!= 0 or y!= 0):
return float(x) / float(y)
def modulo(x, y):
if (x % 2) == 0:
print("This operation is not supported for given input parameters")
else:
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)
try:
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)
Where I'm doing wrong in this code? I'm beginner in Python.