Page 39 - Code & Click - 7
P. 39
Experiential Learning
Lab Activity 2
Program to accept two numeric variables from the user and display their sum and product.
1. Type the code as shown in the image in the Python Editor.
2. Press the F5 key to execute the code. Sample output of the program is given.
DECLARING AND INITIALISING A VARIABLE
Declaring a variable refers to the process of naming the variable and assigning a data type to it. Initialising
a variable refers to the process of assigning a value to the variable. In Python, variables are dynamically
identified by the value they store. Thus, declaring a variable and initializing is done in the same step.
For example, the statement Age = 15 declares a variable named ‘Age’ and initialises it with the
value 15. As 15 is an integer value, the data type of the variable Age is integer.
OPERATORS IN PYTHON
Operators are special symbols that are used to perform a mathematical operation or logical
computation. The values on which the operator performs the task are called Operands. Different
operators work with one or more operands.
Arithmetic Operators
The Arithmetic operators are used to perform mathematical operations on numeric values.
Example
Operator Name Description Output
(X = 20, Y = 3)
+ Addition Adds two numeric values. X + Y 23
– Subtraction Subtracts the second number from the first. X – Y 17
* Multiplication Multiplies two numeric values. X * Y 60
/ Division Divides the first number by the second. X / Y 6.66
Modulus Divides the first number by the second and
% X % Y 2
(Remainder) returns the remainder.
Exponentiation Raises the first number to the power
** X ** Y 800
(Power) represented by the second number.
Integer (floor) Divides the first number by the second and
// X // Y 6
division returns the integer quotient.
37