0% found this document useful (0 votes)
47 views

GRADE XI REVISION 1

The document contains a series of Python programming exercises and theory questions for Grade XI students, focusing on various programming concepts such as loops, data structures, and string manipulation. It includes tasks for writing programs, predicting outputs of code snippets, and differentiating between programming functions. Additionally, it addresses error correction in Python code and requires students to demonstrate their understanding of Python syntax and logic.

Uploaded by

yagnaarani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

GRADE XI REVISION 1

The document contains a series of Python programming exercises and theory questions for Grade XI students, focusing on various programming concepts such as loops, data structures, and string manipulation. It includes tasks for writing programs, predicting outputs of code snippets, and differentiating between programming functions. Additionally, it addresses error correction in Python code and requires students to demonstrate their understanding of Python syntax and logic.

Uploaded by

yagnaarani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

GRADE XI – REVISION

PYTHON PROGRAMS

1. Write a program to print Fibonacci series up to n terms.

2. Write a program to get 5 subject marks as input from the user and calculate the total and
average marks.

3. Write a program to print the series :2,4,8,16…….n

4. Write a program to find the sum of n natural numbers using for loop.

5. Write a program to find the sum of n natural numbers using while loop.

6. Write a program to input the side of a square and calculate its area and volume using
math module.

7. Write a program to print the following pattern

12

123

8. Write a program to print the following pattern

AB

ABC

9. Write a program to search for an element in a given tuple.

10. Write a program to search for an element in a given list.

11. Write a program to find whether the year input by the user is a leap year or not

12. Write a program that repeatedly asks the user to enter roll no. and mark. Store all of
these in a dictionary whose keys are the roll no. and whose values are the marks.

When the user is done entering the roll no and marks, allow them to repeatedly enter a roll
no and print the corresponding mark or a message if the roll no is not in the dictionary.

13. Write a program in Python to input a sentence from user and display all the words start
with upper case letter and its count.

14. Write a program to get list input from the user in L. Then find the elements divisible by 2
and 3 separately and store it as separate lists in L1 and L2.

15. Write a program to find the frequency of elements in a list.

16. Write a program to find the no. of uppercase, lowercase, vowels and consonants in a
sentence.
17. Write a program to get the country name, capital and currency and store it in a
dictionary. Then ask for a country name from the user and print the corresponding capital
and currency.

THEORY QUESTIONS

1. Differentiate between the following

a) break and continue

b) = and ==

c) randint() and randrange() and random()

d) append() and extend() in list

e) pop() and remove() in list

f) title() and capitalize() in strings

g) find() and index() in strings

h) mutable and immutable data types

i) split() and partition in strings

j) ceil() and floor()

OUTPUT BASED QUESTIONS:

1. Write the output of the following python code. (operator precedence)

a) 8 * 3 + 2 ** 3 // 9 – 4

b) 12 > 15 and 8 > 12 or not 19 > 4

c) 2 ** 3 ** 2 + 15 // 3

d) not True and False or True

2. Predict the output of following code:

NUMBER= [15,12,19,26,18]

for i in range (3,0,-1):

A=NUMBER[i]

print(A,end='#')

B=NUMBER[i-1]

print(B,end='@')
3. What will be the output of the following code:
A=20
A=A+20
A=A-10
print(A)
A,B=A-3,33
print(A,B)

4. Predict the output of the following code.


x=10
y=0
while x>y:
x=x-4
y+=4
print(x,end=" ")

5. Predict the output of the following code fragments.


p=10
q=20
p*=q//3
print( “p = “, p)

x=20
x=x+5
x,y=x-1,50
print(“X = “,x ,”Y=”,float(y))

a,b=12,13
c,b=a*2,a/2
print(a,b,c)

6. Look at the sequence of Python statements coded below and find the output.
a=25
b=35
c=45
if((a > 20 or b < 20) and (b > 30 or c > 45)):
print("Welcome to Computer World")
a=a+b
else:
print("Welcome to the Python World")
a=a+c
print(“The value of a is : ”, a)
7. Find the output of the following code fragment.
a = 12
b = 7.4
c=1
a-=b
print( int( a ), b, sep=” & “)
a*=2
b+=a
print(a, b , sep =” & “)

8. Predict the output of the following code fragments.


a) A, B, C = 10, 20, 30
P, Q, R = C-5, A+3, B-4
print( “A, B, C : ”, A, B, C)
print(“ P, Q, R : ”, P, Q, R)

b) X, Y, Z = 8, 4, 12
result = X/Y*Y + Z
print(result)

c) x = 40
y=x+1
x = 20, y+ x
print(x , y)

9. Predict the output of the following code:


a=”[email protected]
s=””
for i in a:
if i.isalpha():
s=s+i.upper()
elif i.isdigit():
s=s+”33”
else:
s=s+”@”
print(s)

10. Write the output of following code segment.


str=”CS and IP”
a=str.split()
print(a)
11. What will be the output of the following code segment:

mylist=[1,2,3,4,5,6,7,8,9,10]

for i in range (0, len(mylist)):


if i%2 == 0 :
print(mylist[i])

12. Find the output of the following code fragments.


stateCapital = {"AndhraPradesh":"Hyderabad","Bihar":"Patna","Maharashtra":"Mumbai",
"Rajasthan":"Jaipur"}

Find the output of the following statements:

i. print(stateCapital.get("Bihar"))
ii. print(stateCapital.keys())
iii. print(stateCapital.values())
iv. print(stateCapital.items())
v. print(len(stateCapital))
vi print("Maharashtra" in stateCapital)
vii. print(stateCapital.get("Assam"))
viii. del stateCapital ["Andhra Pradesh"]
ix. print(stateCapital)

13. What is the length of the tuple shown below?


T=((((‘a’ , 1) , ‘ b ’, ‘ c ‘) , ‘d ‘ , 2), ‘ e ‘, 3 )

14. Find the output of the following.

a)d1={1:10,2:20,3:30,4:40,5:50} b) d1={1:10,2:20,3:30,4:40}

d1.keys() d2={5:50,6:60,7:70}

d1.items() d1.update(d2)

d1.values() print(d1)

c)d1={1:10,2:20,3:30,4:40,5:50,6:60,7:70} d) d1={1:10,2:20,3:30,4:40,5:50}

del d1[3] d1.pop(5)

print(d1) print(d1)

e)d1={1:10,2:20,3:30,4:40,5:50,6:60,7:70}

len(d1)

d1.get(6,60)

d1[6]=65

d1[8]=35

print(d1)
d1.clear()

print(d1)

15. t1=(100,200,”Global”,3,3.5,”Exam”,[1,2],(30,40),3,5,3)). Consider the above tuple t1 and


answer the following questions.

a) len(t1)
b) t1.index(5)
c) t1.count(3)
d) any(t1)
e) t1.index(3,6)

16. What will be the output of the following codes?

s=0
d1={“cat”:12 , ”dog”:6 , ”elephant”:23 , ”bear”:20}
for a in d1:
if len(a)>3:
s=s+d1[a]
print(s)

17. Suggest appropriate functions for the following tasks:

(i) To check whether the string contains digits

(ii) To capitalize all the letters of the string

(iii) To remove all white spaces from the beginning of a string.

(iv) To check whether all letters of the string are in capital letters.

(v) To find for the occurrence of a string within another string

(vi) To covert the first letter of a string to uppercase

(vii) To convert the first letter of each word of a string to uppercase

(viii) To check whether all letters of the string are in lower case letters.

(ix) To check if a string contains only space

18. Write the most appropriate list methods to perform the following task.
a) Delete a given element from the list
b) Get the position of an item in the list
c) Delete the 3rd element from the list
d) Add single element at the end of the list
e) Add an element in the beginning of the list
f) Add elements in the list at the end of the list
19. Write the output for the following Functions:
L1= [34,65,23,98]
L2= [35,86]
i. L1. append (76)
ii. L1. extend(L2)
iii. sum(L1)
iv. L1. count (98)
v. len(L1)
vi. L1. index (76)
vii. min(L1)
viii. max(L2)
ix.L1.pop (3)
x.L2. clear ()
20. Write the output for the following code.
a) L=[ ]
L1=[ ]
L2=[ ]
for i in range(6,10):
L.append(i)
for i in range(10, 4, -2):
L1.append(i)
for i in range(len(L1)):
L2.append(L[ i ] +L1[ i ]
L2.append(len(L) – len( L1))
print(L2)

b) str1=”book”
print(list(str1))

c) L=[2, 4, 5, 6, 2, 3, 4, 4, 7]
count=L.count(4)
print(count)

d) L=[10, 45, 2, 20, 30, 40]


L. sort()
print(L)
L. reverse()
print(L)

e) L=[ ‘ P ‘ , ‘ W’ , ‘R ‘ , ‘ D ‘ , ‘ A ‘]
L . remove(‘R’)
print(L)
print(L.pop())
del L[1]
print( L )
f) L1=[10,20,30,40]
L1.clear()
print(L1)

13. Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3]. What is list1 after list1.pop (1)?
14. Write the output of the following:
L1=[500, 600]
L2=[35, 45]
L1.append(700)
L1.extend(L2)
L1.insert(5,2)
print(L1)
print(L1+L2)
print(L1)
print(L1.index(35))
print(L2*2)
15. L1= [45,65,'The’, [65,'She','He'],90,12,'This',21]
a. L1[3:4] =[“That”,54] b. len(L1)
c. L1[:7] d. L1[1:2] + L1[3:4]

16. Find the data type of the following variables


a) a = [1 , ‘ csc ’, 3.15]
b) b=1 , ‘ csc ’, 3.15
c) d={1:100,2:200,3:300}

17. Consider the following string mySubject:


mySubject = "Computer Science"
What will be the output of the following string operations :
i. print(mySubject[0:len(mySubject)])
ii. print(mySubject[-7:-1])
iii. print(mySubject[::2])
iv. print(mySubject[len(mySubject)-1])
v. print(2*mySubject)
vi. print(mySubject[::-2])
vii. print(mySubject[:3] + mySubject[3:])
viii. print(mySubject.swapcase())
ix. print(mySubject.startswith('Comp'))
x. print(mySubject.isalpha())

18. Consider the following string myAddress:

myAddress = "WZ-1,New Ganga Nagar,New Delhi"

What will be the output of following string operations :

i. print(myAddress.lower())

ii. print(myAddress.upper())

iii. print(myAddress.count('New'))

iv. print(myAddress.find('New'))

v. print(myAddress.rfind('New'))

vi. print(myAddress.split(','))

vii. print(myAddress.split(' '))

viii. print(myAddress.replace('New','Old'))

ix. print(myAddress.partition(','))

x. print(myAddress.index('Agra'))

19. What will be the output of the following statements?

a) >>>list1 = [12,32,65,26,80,10]

>>>list1.sort()

>>>print(list1)

b) >>>list1 = [12,32,65,26,80,10]

>>>sorted(list1)

>>>print(list1)

c) >>>list1 = [1,2,3,4,5,6,7,8,9,10]

>>>list1[::-2]

>>>list1[:3] + list1[3:]

d) >>>list1 = [1,2,3,4,5]

>>>list1[len(list1)-1]
20. Consider the following list myList.

What will be the elements of myList after each of the following operations?

myList = [10,20,30,40]

a) myList.append([50,60])

b) myList.extend([80,90])

21. What will be the output of the following code segment?

myList = [1,2,3,4,5,6,7,8,9,10]

for i in range(0,len(myList)):

if i%2 == 0:

print(myList[i])

22. The record of a student (Name, Roll No, Marks in five subjects and percentage of marks)
is stored in the following list: stRecord = ['Raman','A-36',[56,98,99,72,69], 78.8]

Write Python statements to retrieve the following information from the list stRecord.

a) Percentage of the student

b) Marks in the fifth subject

c) Maximum marks of the student

d) Roll No. of the student

e) Change the name of the student from ‘Raman’ to ‘Raghav’

23. Consider the following tuples, tuple1 and tuple2:

tuple1 = (23,1,45,67,45,9,55,45)

tuple2 = (100,200)

Find the output of the following statements:

i. print(tuple1.index(45))

ii. print(tuple1.count(45))

iii. print(tuple1 + tuple2)

iv. print(len(tuple2))

v. print(max(tuple1))

vi print(min(tuple1))
24. Create the following list using a for loop.

a) A list containing the cube of integers from 1 to 50

b) A list containing the even numbers from 1 to 100

ERROR CORRECTION

1. Rewrite the following code after removing all syntax errors. Underline each
correction you have done in the code:
a=10
for v in range(a)
if v%10=0:
print(v//10)
else if v%8==0:
print(v//8)
else:
print(v//2)

2.Helly has written the following code in python but did not get the expected result.
Help her to rectify the errors. Underline the corrected statements having errors
x,y,z=5 6 7
print(Values are:x,y,z)
z y x =7,6,5
print(z and x)

3. Identify error in the following code. Rewrite the corrected code after removing
errors and underline the corrections:
a,b=input(“Enter value:”)
result=a/*b
print result

4. Rewrite the code after removing the all the syntax errors. Underline each
correction done in the code.
Num=int input(“Enter a number”)
0=sum1
for i in range(10,Num,3)
sum1+=1
if i % 2 =0
print(i * 2)
else
print(i*3)
SLICING:

1. a) Consider the following string mySubject:


mySubject = "Computer Science"
What will be the output of:
i) print(mySubject[:3])
ii) print(mySubject[-5:-1])
iii) print(mySubject[::-1])
iv) print(mySubject*2)

2. Consider the following string mySubject:


mySubject = "Computer Science"
What will be the output of the following string operations:
a) print(mySubject[ 0 : len(mySubject)])
b) print(mySubject[-7 : -1])
c) print(mySubject[ : : 2])
d) print(mySubject[ : : -2])

3. Given a list L=[10,20,30,40,50]


Find the output of the following.
a) L[ : : ]
b) L[2:3]
c) L[3:3]
d) L [--4:-1]

4. What will be stored in variables a,b,c,d,e?


cen=(88, 85, 80, 88, 83, 86)
a=cen[2:2]
b=cen[2:]
c=cen[:2]
d=cen[:-2]
e=cen[2:-2]

5. What will be the output of the following code segment?

a) myList = [1,2,3,4,5,6,7,8,9,10]

del myList[ 3 : ]

print(myList)

b) myList = [1,2,3,4,5,6,7,8,9,10]

del myList[ : 5]

print(myList)
c) myList = [1,2,3,4,5,6,7,8,9,10]

del myList[ : : 2]

print(myList)

MCQ

1. Priyansh wants to store the value 3.5 into a variable n. Which of the following
statement is correct for him?
a) int n=5 b) n=5 c) 5=n d) n=’5’

2. Which of the following is valid identifier?


a) None b) #None c) 0_None d) none

3. What will be the output of the following code segment?


a,b=5,6
b,a=a,b
print(a,”+”,b)
a) 5 + 6 b) 6 + 5 c) 11 d) None

4. a='Computer Science is Science of Computers'

w=a.split(‘Sci’)

print(a[1])

a) Science is b) ence of Computers c) Computer d) ence is

5. Rudra wants to access a second last list element of list object L. Help him to
select an appropriate option to accomplish his task.

a) L[2] b) L[-2] c) L[len(l)-2] d) L-2

6. What will be the value of variable a when loop is terminated?

a=30

while a>0:

print(a)

a-=10

a) 0 b) 10 c) 30 d) -10

7. Observe the given code and select an appropriate output:

a='Welcome 2023'

s=''
for i in a:

if i.isdigit():

s=s+i+'#'

print(s)

a) 2023 b) 2023# c) 20#23 d) 2#0#2#3

8. What will be the value of variable a when loop is terminated?

a=20

for i in range(10,-1,-2):

a=a-2

print(a)

a) 8 b) 0 c) 10 d) 12

9. Suppose tup=(21,22,23) , which one of the following is incorrect?

a) print(tup[1]) b) max(tup) c) print(len(tup)) d) tup[1]=100

10. Choose the correct option

import random

AR= [10,20,30,40,50,60,70]

START = random.randint(1,3)

END= random.randint(2,4)

for k in range(START, END+1):

print(AR[k], end = “#”)

What possible output(s) are expected to be displayed on screen when above


program is executed?

i)10#20#30# iii) 30#40#50#


ii) 50#60#70# iv) 20#30#40#

a) i) and ii) b) iii only c) i), iii) and iv) d) All of these
11. What will be the output of the following code?
d1={"name":"Xxx","DOB":"2000-11-01","marks":90}
d2=d1.copy()
d1["name"]="Yyy"
print("d2:",d2)
a) {'name': 'Xxx', 'DOB': '2000-11-01', 'marks': 90}
b) {'name': 'Yyy', 'DOB': '2000-11-01', 'marks': 90}
c) d2: {'name': 'Xxx', 'DOB': '2000-11-01', 'marks': 90}
d) d2: {'name': 'Yyy', 'DOB': '2000-11-01', 'marks': 90}

12. The function range(-500 , 100 , 100) will yield an iterable sequence like

a) [ 500, 400, 300, 200 ] b) [-500, -400, -300, -200, -100, 0]


c) [-500, -400, -300, -200, -100] d) [-500, 100, 100]

13. Which method is used to convert the string “Python programming is fun” to “Python
Programming Is Fun”?

a) capitalize( ) b) title( ) c) istitle( ) d) All of these

14. Which of the following will give “csc” as the output.


s=”This is csc class”
a) s [ : : -2] b) s [-7:-9] c) s[-7:-10:-1] d) none of these

15. What will be the output of below Python code?


str1="Aplication"
str2=str1.replace('a','A')
print(str2)
a) application b) Application c) ApplicAtion d) applicAtion

16. Which of the following will give "Simon" as output? If str1="John,Simon,Aryan"


a) print(str1[-7:-12]) b) print(str1[-11:-7])
c) print(str1[-11:-6]) d) print(str1[-7:-11])

17. Find the output of the following code.


>>> 4**1**2
a) 4 b) 16 c) 2 d) 8

18. Find the output of the following code.


T=(“Sang” , “Salt” , “Sack”, Sad”)
print(max(T))
a) Sang b) Salt c) Sack d) Sad

You might also like