CLASS XI COMP SCI PYTHON REVISION TOUR
CLASS XI COMP SCI PYTHON REVISION TOUR
IMPORTANT POINTS:
Introduction to Python
• Python is an open source, object oriented HLL developed by Guido van Rossum in 1991
• Tokens - smallest individual unit of a python program.
• Keyword - Reserved word that can’t be used as an identifier
• Identifiers - Names given to any variable, constant, function or module etc.
• Literals - A fixed numeric or non-numeric value.
• Variable - A variable is like a container that stores values to be used in program.
• String - The text enclosed in quotes.
• Comment - Comments are non-executable statement begin with # sign.
• Docstring - Comments enclosed in triple quotes (single or double).
• Operator – performs some action on data
o Arithmetic :- (+,-,*,/,%,**,//)
o Relational/comparison :- (<,>, <=,>=, = =, !=).
o Assignment :- =
o Augmented Assignment :- (/=,+=,-=,*=,%=,**=,//=)
o Logical :- and, or, not
o Membership – in, not in
o Identity :– is, is not
o Bitwise :- (&, |, ~, ^, >>, <<)
• KEYWORDS:-
• PRECEDENCE OF OPERATORS:-
Operator Description
** Exponentiation (raise to the power)
~+- Complement, unary plus and minus (method names for the last two are +@ and -@)
ANS
5 Rewrite the following code in python after removing all syntax error(s).
Underline each correction done in the code.
30=To
for K in range(0,To)
IF k%4==0:
print (K*4)
Else:
print (K+3)
ANS
(i) Python&Java&PHP&HTML&C++&
(ii) Java&PHP&HTML&C++&
(iii) Python&Java&
(iv) Python&Java&PHP&
ANS Option (i),(iii) &(iv) (1½ mark for correct answer)(No partial marking)
Maximum = 4 Minimum=1 ( ½ mark for correct answer)
11 Find and write the output of the following Python code:
def Display(str):
m=""
for i in range(0,len(str)):
if(str[i].isupper()):
m=m+str[i]+'*'
elif str[i].islower():
m=m+'@'
elif str[i]==' ' :
m=m+'#'
print(m)
Display('CracK it')
ANS C*@@@K*#@@
12
(3 MARKS)
ANS 250 # 150
250 # 100
130 # 100
(1 mark each for correct line)
13 Find the output of the following program;
def increment(n):
n.append([4])
return n
l=[1,2,3]
m=increment(l)
print(l,m)
ANS [1, 2, 3, [4]] [1, 2, 3, [4]]
14 Find the error in the given code and correct the code. Underline each correction.
if n==0
print(“Zero”)
elif : n==1
Print(“One”)
elif
n==2:
print(“two”)
else n==3:
print(“Three”)
ANS
15 In the following code, which variables are in same scope and why?
def func1();
A=1
B=2
def func2():
C=3
D=4
E=5
ANS 1. A,B are in same scope as they belong to func1()
2. C,D are in same scope as they belongs to func2()
16 Predict the output of the following code snippets?
arr=[1,2,3,4,5,6]
for i in range(1,6):
arr[i-1]=arr[i]
for i in range(2,6):
print(arr[i], end=" ")
ANS 4566
17 Write the output of the following Python statements.
b=1
for a in range(1, 10, 2):
b += a + 2
print(b)
ANS 36
18 Write the output of the following Python statements.
lst1 = [10, 15, 20, 25, 30]
lst1.insert( 3, 4)
lst1.insert( 2, 3)
print (lst1[-5])
ANS 3
19 What will be the output of the following Python code?
def add (num1, num2):
sum = num1 + num2
sum = add(20,30)
print(sum)
ANS None
20 Evaluate the following expression
16-(4+2)*5+2**3*4
ANS 18
21 What will be the output of the following Python code?
def my_func(var1=100, var2=200):
var1+=10
var2 = var2 - 10
return var1+var2
print(my_func(50),my_func())
ANS 250 300
Dictionary Functions
Some more functions of random module
1) random() -> it returns a random floating point number N in the range [0.0, 1.0]
print(random.random())
2) randint(a,b) -> it returns a random integer in the range (a,b) -> a>=N<=b
print(random.randint(3,5))
3) random.uniform(a,b) -> it returns a random floating point number in the range (a,b) -
> a>=N<=b