Question: 1 2 . 1 2 LAB: Calculator class In the file main.py write a class called Calculator that emulates basic functions of a calculator: addition,
LAB: Calculator class
In the file main.py write a class called Calculator that emulates basic functions of a calculator: addition, subtraction, multiplication, division, and clear. The class has one attribute called calcvalue for the calculator's current value. Implement the following methods as listed below:
Default constructor method to set the attribute to
addition self val add the parameter to the attribute
subtraction self valsubtract the parameter from the attribute
multiplication self val multiply the attribute by the parameter
divisionself val divide the attribute by the parameter
clear self set the attribute to
getvalue self return the attribute
Given two float input values num and num the program outputs the following values:
The initial value of the instance attribute, calcvalue
The value after adding num
The value after multiplying by
The value after subtracting num
The value after dividing by
The value after calling the clear method
Ex: If the input is:
the output is:
class Calculator:
#type your code here
if name "main":
calc Calculator
num floatinput
num floatinput
# The initial value
printfcalcgetvalue:f
# The The value after adding num
calc.additionnum
printfcalcgetvalue:f
# The value after multiplying by
calc.multiplication
printfcalcgetvalue:f
# The value after subtracting num
calc.subtractionnum
printfcalcgetvalue:f
# The value after dividing by
calc.division
printfcalcgetvalue:f
# The value after calling the clear method
calc.clear
printfcalcgetvalue:f
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
