Answer:
Following are the program in the Python programming Language.
#define class
class Alarm:
#define constructor
def __init__(self,code,armed = False):
self.code = code #initialize value
self.armed = armed #initialize value
#define function
def changeCode(self,currentCode,newCode):
#set if conditional statement
if currentCode == self.code:
#initialize value if the condition is true
self.code = newCode
#return value
return newCode
#set object of the class and pass value in constructor
myAlarm=Alarm("93478")
#call and print the function
myAlarm.changeCode("93478","1234")
print(myAlarm.code)
Output:
1234
Explanation:
Here, we define a class "Alarm" and inside the class.
Finally, we set an object of the class and pass value in its parentheses for the constructor and then, we call the function and pass values in its parameter then, we print the code.