2.2 Python as a calculator

mohit355

Mohit Raj

Posted on November 2, 2019

2.2 Python as a calculator

=>> This is 2.2 section of Python tutorial, and i am going to tell u about Python as a calculator. yes,we can use Python shell or any Python IDE as a calculator.

Link of previous linked tutorial
-> 2.1 : https://dev.to/mohit355/python-basics-3cjd
-> 1.2 : https://dev.to/mohit355/download-and-install-python-3-x-1boo

=>> Python is perfectly suited to do basic calculations.

**Along with addition, subtraction, multiplication and division, there is also support for more advanced operations such as:

  1. (+) : Addition
  2. (-) : Subtraction
  3. (*) : Multiplication
  4. (/) : Float division ,return decimal value as output
  5. (//) : Integer division ,return integer value as output
  6. (%) : Modulo ,it will gives reminder
  7. (**) : Exponent Alt TextIn above figure some addational operations shown but don't worry these are function which is predefined in Python that will be discussed later in this series.

Why Python as a Calculator ?

#Ans- .This is because we need not to code many number of line to sum two number or divide or multiply.
we can directly print it using print function. (print function is already discuss in previous post).

For example,

  1. I want to add three number 2,3 and 4. so we directly use print(2+3+4) and its output is 9 as shown below. Alt Text
  2. let's perform following operations : 2+3-4/2
    we can simply done this by print(2+3-4/2) and its output is shown below.
    Alt TextIts print 3.0 because here we use float division and it always return a decimal value

  3. 4%2 output is 0 (% used for the reminder) 4%2 means when 4 is divided by 2 what is the reminder left.
    Alt Text

  4. let's perform 4**2 means 4 to the power 2 and the output is 16.
    Alt Text

=>> So we can do any type of mathematical calculation using simply print function.

=> If you have any problem let me know that in comment box.

Thank You...

💖 💪 🙅 🚩
mohit355
Mohit Raj

Posted on November 2, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

2.2 Python as a calculator
python 2.2 Python as a calculator

November 2, 2019