elif op==16 :
print ("Functions Menu")
print ("j. asinh")
print ("k. acosh")
print ("l. atanh")
fun = raw_input("Choose the function :")
a = float(input("Enter the value :"))
dict6 = {'j':math.asinh(a), 'k':math.acosh(a), 'l':math.atanh(a)}
print ("The result is : " + str(dict6.get(fun)) )
else :
print ("Wrong Choice")
Question:
1. In this program, you will create a class and OOP.
SOLUTION TO THE ABOVE QUESTION
SOLUTION CODE
#Let us import the math library
import cmath
#Create a class and call it calculator
class Calculator:
#define a method a call it trigonometry
def trigonometry(self):
print("Functions Menu")
print("j. asinh")
print("k. acosh")
print("l. atanh")
fun = input("Choose the function :")
if (fun == 'l' or fun == 'k' or fun == 'j'):
a = float(input("Enter the value :"))
dict6 = {'j': cmath.asinh(a), 'k': cmath.acosh(a), 'l': cmath.atanh(a)}
print("The result is : " + str(dict6.get(fun)))
else:
print("Wrong Choice")
# create a new object of Calculator class
my_calc = Calculator()
# Calling object's trigonometry() method
my_calc.trigonometry()
SAMPLE PROGRAM OUTPUT
Comments
Leave a comment