#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()
Question:
1. In this program, you are going to create a with getter and setter.
#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()
#Creating a class for calculating getter and setter
class GetterSetter:
def __init__(self, age = 0):
self._age = age
# getter method
def get_age(self):
return self._age
# setter method
def set_age(self, x):
self._age = x
raj = GetterSetter()
#you can add age using setter
raj.set_age(21)
# this is retrieving age using getter
print(raj.get_age())
print(raj._age)
#The iterations had many mistakes in given code and I fixed it
Comments
Leave a comment