Foundations of Python

20 / 134

Python as a Calculator

We can use Python as a quick and handy calculator. We can perform all the basic four operations - addition, subtraction, multiplication, and division in Python.

Examples

  • To add 4 and 2, use +

    4 + 2
    

    It returns 6

  • To subtract 2 from 4, use -

    4 - 2
    

    It returns 2

  • To multiply 4 and 2, use *

    4 * 2
    

    It returns 8

  • To divide two integers 5 by 2, use / to get the complete value and // to get the integer value

    5 // 2
    

    It returns 2

    5 / 2
    

    It returns 2.5

  • Every line of the code is called expression.

    4 + 2 is one expression and 4 - 2 is another expression.

Run above expressions in the Jupyter notebook on the right-hand side and make yourself comfortable with addition, subtraction, multiplication, and division in Python. Remember to execute the cell in the notebook, press Shift + Enter

INSTRUCTIONS

Peter is driving a car at a speed of 25 kilometres per hour. Calculate the distance covered by him in 4 hours

  • The formula of distance is

    distance = speed * time
    
  • Here speed is 25 and time is 4

  • Multiply 25 and 4 on the right-hand side and execute it

  • Fill in the result of your calculation in the question below

Question -

Distance covered by Peter in 4 hours is kilometres



Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...