Test Index

Python Revision Tour Get it on Google PlayDownload on the App Store CBSE Board Videos

© examsnet.com
Question : 63 of 102
Marks: +1, -0
Write the output displayed on execution of the following Python code :
LS=["HIMALAYA", "NILGIRI", "ALASKA", "ALPS"]
D={}
for S in LS :
if len(S)%4 == 0:
D[S] = len(S)
for K in D :
print(K,D[K], sep = "#")
[CBSE 2024 Set 4]
Solution:  
Output:
HIMALAYA#8
ALPS#4
Explanation:
Lengths: HIMALAYA = 8, NILGIRI = 7, ALASKA = 6, ALPS = 4.
Only lengths divisible by 4 are stored, so D = {'HIMALAYA': 8, 'ALPS': 4}.
The second loop prints each key and its value separated by # (sep="#"), one pair per line.
© examsnet.com
Advertisements
Go to Question: