You are on page 1of 6

KENDRIYA VIDYALAYA AFS MANAURI, PRAYAGRAJ

Computer Science : XI
Practical List : (Term 2)
Session 2021-22
1. Write a program in Python to create the following list and add 10 to each item in the list.
Suppose ListA = [1, 5, 7, 10, 15, 23, 77] then after change list should be-
[11, 15, 17, 21, 33, 87]
2. Write a program in Python to change the item to odd locations with even locations i.e.
item at first with second, third with fourth and so on.
Suppose ListA = [1, 5, 7, 10, 15, 23] Then after change, ListA = [5, 1, 10, 7, 23, 15]
3. Write a program in Python to create a list and change the even numbers to its half and
odd numbers with its double.
Suppose ListA = [4, 5, 7, 10, 12, 13, 6] the after change ListA=[2, 10, 14, 5, 6, 26, 3]
4. Write a program in Python to create a list of numbers and print the smallest and largest
value in the list.
5. Write a program in Python to accept a list of numbers and create two separate lists
which contain even numbers and odd numbers present in the list.
6. Write a program in Python to accept a list of numbers and print second largest and
second smallest number in the list.
7. Write a program in Python to create the following Tuple and print the smallest and
largest value in the TupleAge as TupleAge = (2, 5, 7, 10, 15, 23)
Max : 23 Min 2
8. Write a program in Python to search for a name in the existing tuple of names. Suppose a
Names = (“Amar”, “Akbar”, “Anthony”, “Bhawna”, “Vishal”) and search item is “Bhawna”
the output should be –
Searched Name Bhawna is found at 3 index.
In case of not found of search name, the program should display “Name is not present in
the tuple”
9. Write a Python program to create a tuple T and count the total numbers which are
divisible by 5 in the tuple.
10. Write a program in Python to store item names and price of 5 items in a dictionary and
print Item name and price.
Consider the Dictionary is DItem = {'Pen' :'Rs. 20', 'Eraser' : 'Rs. 3.50', 'Ruler' : 'Rs. 10',
'Copy' : 'Rs. 35', 'Compass' : 'Rs. 70'}
11. Write a program to create Dictionary name DM and save the items with month name as
Keys and number of Days in the month as Value. Also search and print the number of
days present for given month name.
12. Write a program in Python to create a dictionary student containing name and marks of
5 students. Print the number of students secured more than 70 Marks.
Solutions
Q1. Write a program in Python to create the following list and add 10 to each item in the
list. Suppose ListA = [1, 5, 7, 10, 15, 23, 77] then after change, list should be –
[11, 15, 17, 21, 33, 87]
Ans:
#Program to add 10 to each item in the list.
ListA = [1, 5, 7, 10, 15, 23, 77]
print("List before change",ListA)
for i in range(len(ListA)):
ListA[i]= ListA[i]+10
print("List after change",ListA)
Output:
List before change [1, 5, 7, 10, 15, 23, 77]
List after change [11, 15, 17, 20, 25, 33, 87]
Q2. Write a program in Python to change the item to odd locations with even locations i.e.
item at first with second, third with fourth and so on.
Suppose ListA = [1, 5, 7, 10, 15, 23] Then after change, ListA = [5, 1, 10, 7, 23, 15]
Ans:
# program to swap the elements of odd locations with even locations.
ListA = [1, 5, 7, 10, 15, 23]
print("List before change",ListA)
for i in range(0, len(ListA)-1, 2):
ListA[i], ListA[i+1]= ListA[i+1],ListA[i]
print("List after change",ListA)
Output:
List before change [1, 5, 7, 10, 15, 23]
List after change [5, 1, 10, 7, 23, 15]
Q3. Write a program in Python to create a list and change the even numbers to its half and
odd numbers with its double.
Suppose ListA = [4, 5, 7, 10, 12, 13, 6] the after change ListA=[2, 10, 14, 5, 6, 26, 3]
Ans:
# Write a program in Python to create a list and change
# the even numbers to its half and odd numbers with its double.
ListA = eval(input("Enter List"))
print("List before change",ListA)
for i in range(len(ListA)):
if (ListA[i]%2==0):
ListA[i]= ListA[i]//2
else:
ListA[i]= ListA[i]*2
print("List after change",ListA)
Output:
Enter List[4,5,7,10,12,13,6]
List before change [4, 5, 7, 10, 12, 13, 6]
List after change [2, 10, 14, 5, 6, 26, 3]
Q4. Write a program in Python to create a list of numbers and print the smallest and largest
value in the list.
Ans:
# program to find smallest and largest value in the list.
L = eval(input("Enter List"))
mn=mx= L[0]
for i in range(len(L)):
if L[i]<mn:
mn=L[i]
if L[i]>mx:
mx=L[i]
print("Smallest Value",mn)
print("Largest Value",mx)
Output:
Enter List[12,4,5,3,8,9,25,8]
Smallest Value 3
Largest Value 25
Q5. Write a program in Python to accept a list of numbers and create two separate lists
which contain even numbers and odd numbers present in the list.
Ans:
# program to create even and odd list of numbers
L = eval(input("Enter List"))
EL=[]
OL=[]
for i in L:
if i%2==0:
EL.append(i)
else:
OL.append(i)
print("Original List",L)
print("Even List",EL)
print("Odd List",OL)
Output:
Enter List [12,4,5,3,8,9,25,8]
Original List [12, 4, 5, 3, 8, 9, 25, 8]
Even List [12, 4, 8, 8]
Odd List [5, 3, 9, 25]
Q6. Write a program in Python to accept a list of numbers and print second largest and
second smallest number in the list.
Ans:
# program to print second largest and second smallest number in the list.
L = eval(input("Enter List"))
L.sort()
print("Second Smallest Number", L[1])
print("Second Largest Number",L[-2])
Output:
Enter List[12,4,5,3,8,9,25,8]
Second Smallest Number 4
Second Largest Number 12
Q7. Write a program in Python to create the following Tuple and print the smallest and
largest value in the TupleAge as TupleAge = (2, 5, 7, 10, 15, 23)
Max : 23 Min 2
Ans:
# Program to find smallest and largest value in the Tuple.
T = eval(input("Enter tuple"))
mn=mx= T[0]
for i in range(len(T)):
if T[i]<mn:
mn=T[i]
if T[i]>mx:
mx=T[i]
print("Min:",mn)
print("Max:",mx)
Output:
Enter tuple (4,6,2,5,8,9,12,2)
Min: 2
Max: 12
Q8. Write a program in Python to search for a name in the existing tuple of names. Suppose
a Names = (“Amar”, “Akbar”, “Anthony”, “Bhawna”, “Vishal”) and search item is “Bhawna”
the output should be –
Searched Name Bhawna is found at 3 index.
In case of not found of search name, the program should display “Name is not present in
the tuple”
Ans:
# Program to search a name in the tuple of names.
T = eval(input("Enter tuple of names"))
S= input("Enter name to be searched")
if S not in T:
print("Name is not present in the list")
else:
p=T.index(S)
print("Searched Name",S, "is found at ", p,"position")
Output:
Enter tuple of names("Amar","Akbar","Anthony","Bhawna","Vishal")
Enter name to be searched Bhawna
Searched Name Bhawna is found at 3 position
>>>
Enter tuple of names("Amar","Akbar","Anthony","Bhawna","Vishal")
Enter name to be searched Sandhya
Name is not present in the list
Q9. Write a Python program to create a tuple T and count the total numbers which are
divisible by 5 in the tuple.
Ans:
# program to count the numbers divisible by 5 in the tuple.
T = eval(input("Enter tuple of numbers"))
c=0
for i in T:
if i%5==0:
c=c+1
print("Total Numbers divisible by 5 are:",c)
Output:
Enter tuple of numbers (3,5,7,9,10,20,34,25)
Total Numbers divisible by 5 are: 4
Q10. Write a program in Python to store item names and price of 5 items in a dictionary
and print Item name and price.
Consider the Dictionary is DItem = {'Pen' :'Rs. 20', 'Eraser' : 'Rs. 3.50', 'Ruler' : 'Rs. 10',
'Copy' : 'Rs. 35', 'Compass' : 'Rs. 70'}
Ans:
# program to create dictionary and print Items.
d={'Pen' :'Rs. 20', 'Eraser' : 'Rs. 3.50', 'Ruler' : 'Rs. 10',
'Copy' : 'Rs. 35', 'Compass' : 'Rs. 70'}
for i in d:
print(i, d[i])
Output:
Pen Rs. 20
Eraser Rs. 3.50
Ruler Rs. 10
Copy Rs. 35
Compass Rs. 70
Q11. Write a program to create Dictionary name DM and save the items with month name
as Keys and number of Days in the month as Value. Also search and print the number of
days present for given month name.
Ans:
# program to create dictionary of Month-Day and search.
dm={'Jan':31,'Feb':28,'March':31,'April':30,'May':31,'June':30,
'July':31,'Aug':31,'Sep':30,'Oct':31,'Nov':30,'Dec':31}
m=input("Enter Month")
if m in dm:
print("Number of days in",m,"is",dm[m])
else:
print("Wrong Month is given")
Output:
Enter Month Aug
Number of days in Aug is 31
Q12. Write a program in Python to create a dictionary student containing name and marks
of 5 students. Print the number of students secured more than 70 Marks.
Ans:
# program to create dictionary and display name of students who secured
# more than 70 marks.
d={'Amar':72,'Akbar':65,'Anthony':85,'Kabir':70,'Mahak':55,'Komal':77}
for k in d:
if d[k]>70:
print("Name: ",k, "Marks:",d[k])
Output:
Name: Amar Marks: 72
Name: Anthony Marks: 85
Name: Komal Marks: 77

You might also like