Question: Goal: Learn to write accessor and mutator methods for stateful objects. ( Python ) Assignment: Write a class named Calculator that works the following way:
Goal: Learn to write accessor and mutator methods for stateful objects. Python
Assignment: Write a class named Calculator that works the following way:
The init method takes a single float parameter and assigns it to value;
The add method takes a single float parameter, sums it to value and stores it again in value;
The subtract method takes a single float parameter, subtracts it from value and stores it again in value;
The multiply method takes a single float parameter, multiplies it with value and stores it again in value;
The divide method takes a single float parameter, divides value by it stores it again in value and returns None. If the parameter is return "You can't divide by zero!" and do not change the value of value;
The getresult method takes no parameters and returns the value of value.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
