NCERT Solutions Class 11 Computer Science Operators in Python PDF
NCERT Solutions Class 11 Computer Science Operators in Python PDF
NCERT Solutions Class 11 Computer Science Operators in Python PDF
com
Computer Science
Question 1:
Write the output of the given Python code :
a=0
a+ =2
om
print (a)
Answer:
.c
2
ay
Question 2:
od
Write the output of the given Python code :
st
print (3 + 4)
e
print (3 – 4)
di
Answer:
w
7
-1
12
0.75
1
81
0
Question 3:
Write the output of the given Python code :
a = 20
if a > = 22:
print(“if”)
elif a >= 21:
print(“elif”)
else:
print(“else”)
Answer:
else
Question 4:
What is the another name of Comparison Operators?
Answer:
Relational Operators.
om
Question 5:
.c
Which Operator is used for assigning a value into a variable?
ay
Answer:
Assignment Operators.
od
Question 6:
st
Answer:
di
Logical Operators.
tu
Question 7:
.s
Answer:
w
Question 8:
What is the use of operator?
Answer:
The operator subtracts right hand operand from left hand operand.
Question 9:
What is the use of “*” operator?
Answer:
The “*” operator multiplies values on either side of the operator.
Question 10:
What is the use of operator?
Answer:
The 7″ operator divides left hand operand by right hand operand.
Question 11:
What is the use of “%” operator?
Answer:
The “%” operator divides left hand operand by right hand operand and returns remainder.
Question 12:
What is the use of “**” operator?
Answer:
The “**” operator performs exponential (power) calculation on operators.
Question 13:
om
What is the use of 7/” operator?
Answer:
.c
The 7/” operator results is the quotient in which the digits after the decimal point are
removed. ay
od
Question 14:
What is the use of “= =” operator?
st
Answer:
e
It checks if the value of two operands are equal or not, if yes then condition becomes true.
di
tu
Question 15:
What is the use of “! =” operator?
.s
Answer:
w
It checks if the value of two operands are equal or not, if values are not equal then condition
becomes true.
w
w
Question 16:
Why do we use ” < > “operator?
Answer:
It checks if the value of two operands are equal or not, if values are not equal then condition
becomes true.
Question 17:
Describe the use of “>” operator?
Answer:
It checks if the value of left operand is greater than the value of right operand, if yes then
condition becomes true.
Question 18:
Why we use “<” operator?
Answer:
The “<” operator checks if the value of left operand is less than the value of right operand, if
yes then condition becomes true.
Question 19:
What value has been check by ” > = ” operator?
Answer:
It checks if the value of left operand is greater than or equal to the value of right operand, if
yes then condition becomes true.
Question 20:
Write syntax for “greater than or equal to” operator.
om
Answer:
a>=b
.c
Question 21: ay
What value have been check by ” < = ” operator?
od
Answer:
It checks if the value of left operand is less than or equal to the value of right operand, if yes
st
Question 22:
Is ” < =” a Assignment operator ?
tu
Answer:
.s
Question 23:
w
1 word = ‘word’
2 print word._len_()
Answer:
1 word = ‘word’
2 print len(word)
Question 24:
How many types of operations are supported by the Python language ?
Answer:
Python language supports the following types of operations.
• Arithmetic operations
• Comparison (i.e. Rotational) operations
• Assignment operations
• Logical operations
• Bitwise operations
• Membership operations
• Identity operations.
Question 25:
What will be the output of the following code :
1a=1
2 a, b = a+1, a+1
3 print a
om
4 print b
.c
Answer:
ay
2
od
2
st
Question 26:
e
Answer:
tu
No.
.s
w
Question 1:
What do you mean by Operator precedence?
Answer:
Operator precedence determines the grouping of terms in an expression. This affects how
an expression is evaluated. Certain operators have higher precedence than others; for
example, the multiplication operator has higher precedence than the addition operator.
Question 2:
Assume if A = 60; and B = 13; then find the values of the following :
A&B
A|B
Answer:
Here in binary format they will be as follows:
A = 0011 1100
B = 0000 1101
hence
A&B = 0000 1100 and A|B = 00111101
Question 3:
Assume if A = 60; and B = 13, then find the values of the following.
A ∧ Band ~A
Answer:
Here in binary format they will be as follows :
A = 00111100 B = 0000 1101
hence
A ∧ B = 0011 0001 and ~A = 1100 0011
Question 4:
Explain assigning values to variables in Python.
om
Answer:
Python variables do not have to be explicitly declared to reserve memory space. The
.c
declaration happens automatically when you assign a value to a variable. The equal sign (=)
is used to assign values to variables. ay
od
The operand to the left of the = operator is the name of the variable, and the operand to the
right of the = operator is the value stored in the variable.
st
For example:
# !/usr/bin/python
e
print miles
w
print name
w
while running this program, this will produce the following result:
100
w
1000.0
John
Question 5:
Write the output of the following Python code
a=6
b=7
c = 42
print 1, a = = 6
print 2, a = = 7
print 3, a = = 6 and b = = 7
print 4, a = = 7 and b = = 7
Answer:
1 True
2 False
3 True
4 False
5 True
6 True
om
7 False
8 True
.c
9 False
ay
Question 6:
od
What do you mean by expression “a = 5” ?
Answer:
st
This statement assigns the integer value 5 to the variable a. The part at the left of the
assignment operator (=) is known as the 1 value (left value) and the right one as the r value
e
(right value). The l value has to be a variable whereas the l value can be either a constant, a
di
Question 7:
What do you mean by statement in Python?
w
Answer:
w
A statement is an instruction that the Python interpreter can execute. We have seen two
w
Question 8:
What do you mean by expression in Python ?
Answer:
An expression is a combination of values, variables, and operators. If you type an expression
on the command line, the interpreter evaluates it and displays the result:
Question 9:
Explain Operators and Operands?
Answer:
Operators are special symbols that represent computations like addition and multiplication.
The values the operator uses are called Operands.
Question 10:
Use IDLE to calculate : [CBSE Text Book]
(a) 6 + 4 * 10
(b) (6 + 4) * 10
Answer:
(a) 6 + 40 = 46
(b) 10 * 10 = 100
om
Question 11:
.c
What will be the output of the following code : [CBSE Text Book]
a = 3 – 4 + 10 b = 5 * 6 c = 7.0/8.0 ay
Answer:
Print “These are the values a, b, c.
od
These are the values : 9300.0.
st
Question 1:
tu
programming language:
w
w
# !/usr/bin/python
a = 21
b = 10
c=0
if (a = = b ):
print “Line 1 – a is equal to b”
else:
print “Line 1 – a is not equal to b”
if ( a ! = b ):
print “Line 2 – a is not equal to b”
else:
print “Line 2 – a is equal to b”
if (a <> b):
print “Line 3 – a is not equal to b”
else:
om
if (b > = a):
print “Line 7 – b is either greater than or equal to b”
.c
else:
ay
print “Line 7 – b is neither greater than nor equal to b”
od
When you execute the above program it produces following result:
st
Question 2:
w
# !/usr/bin/python
a = 21
b = 10
c=0
c=a+b
print “Line 1 – Value of c is “, c
c = a -b
print “Line 2 – Value of c is “, c
c=a*b
om
When you execute the above program it produces following result:
.c
Line 1 – Value of c is 31
Line 2 – Value of c is 11 ay
Line 3 – Value of c is 210
Line 4 – Value of c is 2
od
Line 5 – Value of c is 1
Line 6 – Value of c is 8
st
Line 7 – Value of c is 2
e
di
Question 3:
tu
programming language :
w
w
# !/usr/bin/python
a = 21
b = 10
c=0
c=a+b
print “Line 1 – Value of c is “, c
c += a
print “Line 2 – Value of c is “, c
c *= a
print “Line 3 – Value of c is “, c
c/= a
print “Line 4 – Value of c is “, c
c=2
c %= a
print “Line 5 – Value of c is “, e
c**= a
print “Line 6 – Value of c is “, c
c//= a
print “Line 7 – Value of c is “, c
om
When you execute the above program it produces following result:
.c
Line 1 – Value of c is 31
Line 2 – Value of c is 52 ay
Line 3 – Value of c is 1092
Line 4 – Value of c is 52
od
Line 5 – Value of c is 2
Line 6 – Value of c is 2097152
st
Question 4:
tu
Following example to understand all the bitwise operators available in Python programming
w
language:
w
w
# !/usr/bin/python
a = 60 # 60 = 0011 1100
b = 13 # 13 = 0000 1101
c=0
c = a | b; # 61 = 0011 1101
print “Line 2 – Value of c is “, c
c = a ∧ b; # 49 = 0011 0001
print “Line 3 – Value of c is “, c
om
Line 1 – Value of c is 12
.c
Line 2 – Value of c is 61
Line 3 – Value of c is 49 ay
Line 4 – Value of c is -61
Line 5 – Value of c is 240
od
Line 6 – Value of c is 15
st
Question 5:
e
Answer:
tu
Following example to understand all the logical operators available in Python programming
language:
.s
w
#!/usr/b in/python
w
w
a = 10
b = 20
c=0
if (a and b):
print “Line 1 – a and b are true”
else:
print “Line 1 – Either a is not true or b is not true”
if (a or b):
print “Line 2 – Either a is true or b is true or both are true”
else:
print “Line 2 – Neither a is true nor b is true”
a=0
if ( a and b ):
print “Line 3 – a and b are true”
else:
print “Line 3 – Either a is not true or b is not true”
if ( a or b ):
print “Line 4 – Either a is true or b
is true or both are true”
else:
print “Line 4 – Neither a is true nor b is true”
if not( a and b) :
print “Line 5 – a and b are true” else:
print “Line 5 – Either a is not true or b is not true”
om
When you execute the above program it produces following result:
.c
Line 1 – a and b are true ay
Line 2 – Either a is true or b is true or both are true
od
Line 3 – Either a is not true or b is not true
Line 4 – Either a is true or b is true or both are true
st
Question 6:
Write source in Python code for membership operators.
tu
Answer:
.s
#!/usr/bin/python
w
a = 10
b = 20
list = [1,2,3,4, 5 ];
if ( a in list):
print “Line 1 – a is available in the given list”
else:
print “Line 1 – a is not available in the given list”
if (b not in list):
print “Line 2 – b is not available in the given list”
else:
print “Line 2 – b is available in the given list”
a=2
if ( a in list):
print “Line 3 – a is available in the given list”
else:
print “Line 3 – a is not available in the given list”
Question 7:
Write source in Python code for identity operators.
om
Answer:
Following example to understand all the identity operators available in Python programming
.c
language :
ay
# !/usr/bin/py thon
od
a = 20
st
b = 20
e
di
if (a is b):
tu
else:
w
same identity”
if (id(a) = = id(b)):
w
if (a is not b ):
print “Line 4 – a and b do not have
same identity”
else:
Question 11:
om
Give example to understand operator precedence available in Python programming
language.
Answer:
.c
Following example to understand operator precedence available in Python programming
ay
language :
od
#!/usr/bin/python
st
a = 20
e
b = 10
di
c = 15
tu
d=5
e=0
.s
e = (a + b)*c/d #(30*15)/5
w
print “Value of (a + b) * c / d is “, e
w
w
e = a + (b*c)/d; # 20 + (150/5)
print “Value of a + (b * c) / d is “, e
Value of (a + b) * c / d is 90
Value of ((a + b) * c) / d is 90
Value of (a + b) * (c / d) is 90
Value of a + (b * c) / d is 50
Question 12:
How are comments written in a program ?
Answer:
As the program gets bigger, it becomes difficult to read it, and to make out what it is doing
by just looking at it. So it is good to add notes to the code, while writing it. These notes are
known as comments. In Python, comment start with ‘#’ symbol. Anything written after # in a
line is ignored by interpreter, i.e. it will not have any effect on the program.
For example,
# calculating area of a square > > > area = side * * 2
For adding multi-line comment in a program :
(i) Place ‘#’ in front of each line, or,
om
(ii) Use triple quoted string. They will only work as comment, when they are not being used
as docstring
.c
ay
od
st
e
di
tu
.s
w
w
w