View on GitHub

python-for-kids

Learning and exercise content on Python for Kids

Day 19 - Putting it all together

There are many more left to learn in Python. Explore and learn. Becuase learning a programming language never ends. A programming language always brings in new changes which you need to keep learning. Only when you stop learning a programming language either because you are bored or the language itself is dead.

Let’s build a complete calculator

class Calculator:
    def __init__(self, num1, num2):
        self.a = num1
        self.b = num2

    # addition
    def addition(self):
        result = self.a + self.b
        print("Addition:        " + str(result))

    # subtraction
    def subtraction(self):
        result = self.a - self.b
        print("Subtraction:     " + str(result))

    # multiplication
    def multiplication(self):
        result = self.a * self.b
        print("Multiplication:  " + str(result))

    # division
    def division(self):
        result = self.a / self.b
        print("Division:        " + str(result))

#Calling the class
mycalc = Calculator(20, 10)
mycalc.addition()
mycalc.subtraction()
mycalc.multiplication()
mycalc.division()

Building calculator app using our learnings

Day 19 - Exercise

  1. Take input while calling the calculator object.
  2. Add condition that a should be greater than b when subtracting.

Next: Day 20 - Learning Resources

Back to Index