Login using Social Account
Login using your credentials
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
6
To subtract 2 from 4, use -
-
4 - 2
It returns 2
2
To multiply 4 and 2, use *
*
4 * 2
It returns 8
8
To divide two integers 5 by 2, use / to get the complete value and // to get the integer value
/
//
5 // 2
5 / 2
It returns 2.5
2.5
Every line of the code is called expression.
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
Shift + Enter
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
25
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
Taking you to the next exercise in seconds...
Stay here Next Exercise
Want to create exercises like this yourself? Click here.
Note - Having trouble with the assessment engine? Follow the steps listed here
1 Why Programming?
2 A Quick Introduction
3 Python as a Calculator
4 Order of Operations in Python
5 Advanced Operations in Python
6 Variables in Python
7 Calculations with Variables
8 Hands-on on Python Variables
9 Types of Variables in Python
10 Guess the Type
11 Operations with Other Types
12 Functions
13 Built-in Functions
14 Type Conversion Functions
15 Math Functions
16 Random Number Generation
17 Making your own functions
18 Flow of Execution
19 Parameters and Arguments
20 Types of Functions
21 Input from User
22 Comments
23 Boolean Expressions
24 Logical Operators
25 Conditional Execution
26 Visualize the Conditional
27 Catching Exceptions
28 Updating Variables
29 While loop
30 Break and Continue
31 For loop
32 Strings
33 String Slices
34 Immutability of Strings
35 in Operator
36 String methods
37 Parsing Strings
38 Format Operator
39 Lists
40 Lists v/s Strings
41 List Methods
42 Deleting Elements of List
43 Lists and Strings
44 Dictionaries
45 Working with Dictionaries
46 Tuples
47 Working with Tuples
48 Comparison with Tuples
49 Tuple Assignment
50 Tuples and Dictionaries
51 Python - Understanding Files
52 Reading Files
53 Searching in Files
54 Writing Files
Loading comments...