GRADE XI REVISION 1
GRADE XI REVISION 1
PYTHON PROGRAMS
2. Write a program to get 5 subject marks as input from the user and calculate the total and
average marks.
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.
12
123
AB
ABC
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.
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
b) = and ==
a) 8 * 3 + 2 ** 3 // 9 – 4
c) 2 ** 3 ** 2 + 15 // 3
NUMBER= [15,12,19,26,18]
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)
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 =” & “)
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)
mylist=[1,2,3,4,5,6,7,8,9,10]
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)
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}
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)
a) len(t1)
b) t1.index(5)
c) t1.count(3)
d) any(t1)
e) t1.index(3,6)
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)
(iv) To check whether all letters of the string are in capital letters.
(viii) To check whether all letters of the string are in lower case letters.
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)
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]
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(','))
viii. print(myAddress.replace('New','Old'))
ix. print(myAddress.partition(','))
x. print(myAddress.index('Agra'))
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])
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.
tuple1 = (23,1,45,67,45,9,55,45)
tuple2 = (100,200)
i. print(tuple1.index(45))
ii. print(tuple1.count(45))
iv. print(len(tuple2))
v. print(max(tuple1))
vi print(min(tuple1))
24. Create the following list using a for loop.
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:
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’
w=a.split(‘Sci’)
print(a[1])
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=30
while a>0:
print(a)
a-=10
a) 0 b) 10 c) 30 d) -10
a='Welcome 2023'
s=''
for i in a:
if i.isdigit():
s=s+i+'#'
print(s)
a=20
for i in range(10,-1,-2):
a=a-2
print(a)
a) 8 b) 0 c) 10 d) 12
import random
AR= [10,20,30,40,50,60,70]
START = random.randint(1,3)
END= random.randint(2,4)
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
13. Which method is used to convert the string “Python programming is fun” to “Python
Programming Is Fun”?