Delhi Public School, R.K.
Puram Computer Science
1. Write a program in Python
● To accept 8 numbers, store them in a list NUMS
● To add adjacent pair of elements of NUMS and store it in another list MNUMS
● To copy the content of MNUMS on alternate places in the NUMS starting from second place of
NUMS.
● To display content of NUMS as well as MNUMS
Example:
8
7
6
5
4
3
2
1
Original Content [NUMS] -> [8, 7, 6, 5, 4, 3, 2, 1]
8 + 7 = 15
6 + 5 = 11
4 + 3 = 7
2 + 1 = 3
[NUMS] -> [8, 15, 6, 11, 4, 7, 2, 3]
[MNUMS] -> [15, 11, 7, 3]
# --------------------------------------------------------------#
# List-Program No : L5-P6
# Developed By : Suhani Mishra
# Date : 17-Jan-2025
# --------------------------------------------------------------#
NUMS=[]
print("Enter 8 numbers:")
for i in range(8):
NUMS.append(int(input()))
print("Original Content [NUMS] ->", NUMS)
MNUMS=[]
for i in range(0,len(NUMS),2):
add=NUMS[i]+NUMS[i+1]
MNUMS.append(add)
for i in range(0,len(MNUMS)):
NUMS[i+1]=MNUMS[i]
print("[NUMS] ->", NUMS)
print("[MNUMS] ->", MNUMS)
‘ ‘ ‘ Output:
Enter 8 numbers:
8
7
6
5
4
3
2
1
Original Content [NUMS] -> [8, 7, 6, 5, 4, 3, 2, 1]
[NUMS] -> [8, 15, 11, 7, 3, 3, 2, 1]
[MNUMS] -> [15, 11, 7, 3]
‘ ‘ ‘
Programming Practical List 5 CScXI/2024_2025/L5 #1/9
Delhi Public School, R.K.Puram Computer Science
2. Given a tuple ALL = (5, 8, 2, 'apple', 'banana', 'Grapes'), Write a Python code
I. to print the second to fourth elements of the tuple ALL.
II. to print the content of ALL with its content reversed.
# --------------------------------------------------------------#
# List-Program No : L5-P2
# Developed By : Suhani Mishra
# Date : 17-Jan-2025
# --------------------------------------------------------------#
ALL=(5, 8, 2, 'apple', 'banana', 'Grapes')
print("Second to fourth elements:", ALL[1:4])
print("Reversed content of ALL:", ALL[::-1])
‘ ‘ ‘ Output:
Second to fourth elements: (5,8,2,’apple)
Reversed content of ALL: ('Grapes', ‘banana’, ‘apple’, 2, 8, 5)
‘ ‘ ‘
3. Consider the following tuples
Main = ('Roti', 'Sabji', 'Dal')
Addon = ('Papad', 'Salad')
Write a Python code
I. to concatenate content of both the tuples and create another tuple Meal.
II. to display the content of Meal.
# --------------------------------------------------------------#
# List-Program No : L5-P3
# Developed By : Suhani Mishra
# Date : 17-Jan-2025
# --------------------------------------------------------------#
Main = ('Roti' , 'Sabji' , 'Dal')
Addon = ('Papad' , 'Salad')
Meal = Main + Addon
print("The contents of the Meal:" , Meal)
‘ ‘ ‘ Output:
The contents of the Meal: ('Roti', 'Sabji', 'Dal', 'Papad', 'Salad')
‘ ‘ ‘
4. Write a Python code to unpack the content of tuple ('Neeraj', 'A-8, ABC Nagar', 2500,
'Male', True) and store the results in variables Name, Address, Fee, Gender and Indian.
Display the unpacked content from the variables.
# --------------------------------------------------------------#
# List-Program No : L5-P4
# Developed By : Suhani Mishra
# Date : 17-Jan-2025
# --------------------------------------------------------------#
Programming Practical List 5 CScXI/2024_2025/L5 #2/9
Delhi Public School, R.K.Puram Computer Science
data=('Neeraj','A-8, ABC Nagar', 2500, 'Male', True)
Name, Address, Fee, Gender, Indian=data
print("Name:", Name)
print("Address:", Address)
print("Fee:", Fee)
print("Gender:", Gender)
print("Indian:", Indian)
‘ ‘ ‘ Output:
Name: Neeraj
Address: A-8, ABC Nagar
Fee: 2500
Gender: Male
Indian: True
‘ ‘ ‘
5. Given the tuple Scores = (1, 2, 3, 4, 2, 5, 2, 3, 4, 2, 1). Write a Python code to find
the count of occurrences of each score from the tuple and display the result in the following format.
Score Frequency
1 2
2 4
3 2
4 2
5 1
# --------------------------------------------------------------#
# List-Program No : L5-P5
# Developed By : Suhani Mishra
# Date : 17-Jan-2025
# --------------------------------------------------------------#
Scores=(1, 2, 3, 4, 2, 5, 2, 3, 4, 2, 1)
frequency=[0,0,0,0,0]
for i in Scores:
if i==1:
frequency[0]+=1
elif i==2:
frequency[1]+=1
elif i==3:
frequency[2]+=1
elif i==4:
frequency[3]+=1
elif i==5:
frequency[4]+=1
print("Score Frequency")
for score in range(len(frequency)):
print(score+1, end="\t")
print(frequency[score])
‘ ‘ ‘ Output:
Score Frequency
1 2
2 4
3 2
4 2
5 1
‘ ‘ ‘
Programming Practical List 5 CScXI/2024_2025/L5 #3/9
Delhi Public School, R.K.Puram Computer Science
6. Write a program in Python
● To accept item numbers of 5 items, store them in a list INO
● To accept item names of 5 items, store them in a list INAME
● To create a dictionary ITEM with Key-Value pair with Keys from INO and corresponding Values from
INAME
● To display the content of INO and INAME
● To display the content of ITEM in ascending order of item numbers
# --------------------------------------------------------------#
# List-Program No : L5-P6
# Developed By : Suhani Mishra
# Date : 17-Jan-2025
# --------------------------------------------------------------#
INO=[]
print("Enter item numbers:")
for i in range(5):
INO.append(int(input()))
INAME=[]
print("Enter names of items:")
for i in range(5):
INAME.append(input())
ITEM={}
for i in range(5):
ITEM={INO[i]:INAME[i]}
print("INO:", INO)
print("INAME:", INAME)
print("Sorted ITEMS:")
for i in sorted(ITEM):
print(i, ITEM[i])
‘ ‘ ‘ Output:
Enter item numbers:
2
3
4
5
7
Enter names of items:
dogs
chairs
tables
balls
pens
INO: [2, 3, 4, 5, 7]
INAME: ['dogs', 'chairs', 'tables', 'balls', 'pens']
Sorted ITEMS:
2 dogs
3 chairs
4 tables
5 balls
7 pens
‘ ‘ ‘
7. A. Assign the following contents in a tuple Names
"JAYA", "AMAR", "PRIYA", "AKBAR", "RESHMA", "ANTHONY"
Programming Practical List 5 CScXI/2024_2025/L5 #4/9
Delhi Public School, R.K.Puram Computer Science
B. Assign the following contents in a tuple Marks
75, 56, 86, 92, 65, 86
● Create a dictionary Results with keys from tuple Names and corresponding values from tuple
Marks.
● Display the content of Results with keys arranged alphabetically in ascending order.
● Display the content of values of Results arranged in ascending order.
● Create a new dictionary named Toppers to store only such items of dictionary Results where
marks are more than 80.
# --------------------------------------------------------------#
# List-Program No : L5-P7
# Developed By : Suhani Mishra
# Date : 17-Jan-2025
# --------------------------------------------------------------#
Names=("JAYA", "AMAR", "PRIYA", "AKBAR", "RESHMA", "ANTHONY")
Marks=(75, 56, 86, 92, 65, 86)
Results=dict(zip(Names,Marks))
print("Results arranged in alphabetical order of names: ")
for names in sorted(Results):
print("Name: ",names,",Marks: ",Results[names])
Toppers = {}
for name in Results:
if Results[name] > 80:
Toppers[name] = Results[name]
print("Toppers:")
print(Toppers)
‘ ‘ ‘ Output:
Results arranged in alphabetical order of names:
Name: AKBAR ,Marks: 92
Name: AMAR ,Marks: 56
Name: ANTHONY ,Marks: 86
Name: JAYA ,Marks: 75
Name: PRIYA ,Marks: 86
Name: RESHMA ,Marks: 65
Toppers:
{'PRIYA': 86, 'AKBAR': 92, 'ANTHONY': 86}
‘ ‘ ‘
8. Write a Python code to perform the following:
● To accept 8 numbers in a loop, store them in a Tuple T (with the help of re-assignment method)
● To display the content of T in reverse order
● To add and display the sum of values stored in T
● To find and display minimum and maximum values present in T
● To display sum of each adjacent pair of values
● To find those pairs (any pair 1st-2nd, 1st-5th, 3rd-6th,...) of values from the content of T, whose
sum is the same as one of the values in the tuple T.
# --------------------------------------------------------------#
# List-Program No : L5-P8
# Developed By : Suhani Mishra
# Date : 17-Jan-2025
# --------------------------------------------------------------#
Programming Practical List 5 CScXI/2024_2025/L5 #5/9
Delhi Public School, R.K.Puram Computer Science
T = ()
for i in range(8):
num=int(input('Enter number: '))
T+=(num,)
print(T)
print('Content of T in reverse order')
print(T[::-1])
sum_of_T = sum(T)
print("Sum of values in T:", sum_of_T)
min_value = min(T)
max_value = max(T)
print("Minimum value in T:", min_value)
print("Maximum value in T:", max_value)
print('Sum of each adjacent pair of values:')
for i in range(len(T)-1):
adjacentsum=T[i]+T[i+1]
print('Sum of', T[i],'and',T[i+1],'is',adjacentsum)
print('Pairs whose sum is equal to one of the values in T:')
for i in range(len(T)):
for j in range(i+1, len(T)):
pair_sum = T[i] + T[j]
if pair_sum in T:
print('Sum of', T[i], 'and', T[j], 'is', pair_sum)
‘ ‘ ‘ Output:
Enter number: 2
Enter number: 4
Enter number: 3
Enter number: 1
Enter number: 5
Enter number: 6
Enter number: 11
Enter number: 7
(2, 4, 3, 1, 5, 6, 11, 7)
Content of T in reverse order
(7, 11, 6, 5, 1, 3, 4, 2)
Sum of values in T: 39
Minimum value in T: 1
Maximum value in T: 11
Sum of each adjacent pair of values:
Sum of 2 and 4 is 6
Sum of 4 and 3 is 7
Sum of 3 and 1 is 4
Sum of 1 and 5 is 6
Sum of 5 and 6 is 11
Sum of 6 and 11 is 17
Sum of 11 and 7 is 18
Pairs whose sum is equal to one of the values in T:
Sum of 2 and 4 is 6
Sum of 2 and 3 is 5
Sum of 2 and 1 is 3
Sum of 2 and 5 is 7
Sum of 4 and 3 is 7
Sum of 4 and 1 is 5
Sum of 4 and 7 is 11
Sum of 3 and 1 is 4
Sum of 1 and 5 is 6
Programming Practical List 5 CScXI/2024_2025/L5 #6/9
Delhi Public School, R.K.Puram Computer Science
Sum of 1 and 6 is 7
Sum of 5 and 6 is 11
‘ ‘ ‘
9. Write a Python code to perform the following:
● To initialize a tuple WD containing (1,2,3,4,5,6,7)
● To initialize a list WDN containing ['SUN','MON','TUE','WED','THU','FRI','SAT']
● To create a dictionary W with key-value pairs with corresponding values from WD and WDN
● To display content of W
● To re-arrange the content of dictionary in such a way that it becomes as follows:
{1:'MON',2:'TUE',3:'WED',4:'THU,5:'FRI',6:'SAT',7:'SUN'}
● To display the content of W
● To copy the partial content of W in dictionaries MyDays and OfficeDays, MyDays should have
content from keys 2,4 and 7 and rest from W to become the content of OfficeDays.
● To display the contents of MyDays and OfficeDays
# --------------------------------------------------------------#
# List-Program No : L5-P9
# Developed By : Suhani Mishra
# Date : 17-Jan-2025
# --------------------------------------------------------------#
WD = (1, 2, 3, 4, 5, 6, 7)
WDN = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
W = {}
for i in range(len(WD)):
W[WD[i]] = WDN[i]
print(‘W=’, W)
W[1], W[2], W[3], W[4], W[5], W[6], W[7] = 'MON', 'TUE', 'WED', 'THU', 'FRI',
'SAT', 'SUN'
print(‘W=’, W)
MyDays = {W[2], W[4], W[7]}
OfficeDays = {}
for k in W:
if W[k] not in MyDays:
OfficeDays[k]=W[k]
print('My Days:',MyDays)
print('Office Days:',OfficeDays)
‘ ‘ ‘ Output:
W={1: 'SUN', 2: 'MON', 3: 'TUE', 4: 'WED', 5: 'THU', 6: 'FRI', 7: 'SAT'}
W={1: 'MON', 2: 'TUE', 3: 'WED', 4: 'THU', 5: 'FRI', 6: 'SAT', 7: 'SUN'}
My Days: {'SUN', 'THU', 'TUE'}
Office Days: {1: 'MON', 3: 'WED', 5: 'FRI', 6: 'SAT'}
‘ ‘ ‘
10. Write a Python code to perform the following operations:
● To initialize a tuple TL=('RED','YELLOW','GREEN')
● To accepts names of 10 colors from user and store them in a list CL
● To display the color names from CL along with corresponding message "TRAFFIC LIGHT" and
"NOT TRAFFIC LIGHT" after checking from the content of TL
● To initialize another tuple TM=('STOP','BE READY TO START/STOP','GO')
● To create a dictionary TLM by combining corresponding key-value pairs from TL and TM.
● To display the content of TLM
Programming Practical List 5 CScXI/2024_2025/L5 #7/9
Delhi Public School, R.K.Puram Computer Science
# --------------------------------------------------------------#
# List-Program No : L5-P10
# Developed By : Suhani Mishra
# Date : 17-Jan-2025
# --------------------------------------------------------------#
TL = ('RED', 'YELLOW', 'GREEN')
CL = []
for i in range(10):
color = input('Enter color number ' + str(i+1) + ': ')
CL.append(color)
for color in CL:
if color.upper() in TL:
print("TRAFFIC LIGHT:", color)
else:
print("NOT TRAFFIC LIGHT:", color)
TM = ('STOP', 'BE READY TO START/STOP', 'GO')
TLM = {}
for i in range(len(TL)):
TLM[TL[i]] = TM[i]
print("Traffic Light Messages Dictionary (TLM):")
print(TLM)
‘ ‘ ‘ Output:
Enter color number 1: orange
Enter color number 2: blue
Enter color number 3: green
Enter color number 4: yellow
Enter color number 5: red
Enter color number 6: purple
Enter color number 7: grey
Enter color number 8: pink
Enter color number 9: violet
Enter color number 10: indigo
NOT TRAFFIC LIGHT: orange
NOT TRAFFIC LIGHT: blue
TRAFFIC LIGHT: green
TRAFFIC LIGHT: yellow
TRAFFIC LIGHT: red
NOT TRAFFIC LIGHT: purple
NOT TRAFFIC LIGHT: grey
NOT TRAFFIC LIGHT: pink
NOT TRAFFIC LIGHT: violet
NOT TRAFFIC LIGHT: indigo
Traffic Light Messages Dictionary (TLM):
{'RED': 'STOP', 'YELLOW': 'BE READY TO START/STOP', 'GREEN': 'GO'}
‘ ‘ ‘
IMPORTANT: REFER TO MORE QUESTIONS GIVEN IN THE ASSIGNMENT BOOKLET
General Instructions:
i. Type and execute the solutions of the above mentioned problems on IDLE/colab
ii. Type the following on top of your program code with desired information about each of your programs
as comment line (in the same format) - It is mandatory to use Courier New/Fixed Size Font
with Style - BOLD & Size - 11 or 12 in all the programs and also use single line spacing to
avoid wastage of papers:
'''Program No : 01 (Practical List 5)
Developed By : Aarya Singhraj
Programming Practical List 5 CScXI/2024_2025/L5 #8/9
Delhi Public School, R.K.Puram Computer Science
Class Section : XI H
Date : 09-Dec-2024'''
iii. On successful execution, copy and paste the sample output at the bottom of the program as comment
lines. Give program filename as per list and practical number as L5P1.PY, L5P2.PY,...
iv. Save all the programs in a google folder with a name as <Section>-<YourName>-CS (Example:
XI-H-RAMESH-CS) and share with CS Teacher. Take a hard copy (printout) of the program and get it
signed from the respective CS teacher along with an index entry in a Practical File.
Programming Practical List 5 CScXI/2024_2025/L5 #9/9