Question:medium

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 = "#")
    

Show Hint

Use the len()} function to calculate the length of strings, and the \%} operator to check divisibility conditions in Python loops.
Updated On: Jan 13, 2026
Show Solution

Solution and Explanation

Output:
HIMALAYA#8
ALPS#4
    
Explanation: The list `LS` is `["HIMALAYA", "NILGIRI", "ALASKA", "ALPS"]`. The program iterates through `LS`. For each string, if its length is a multiple of 4, the string and its length are added to dictionary `D`. After processing, `D` is `{"HIMALAYA": 8, "ALPS": 4}`. The program then prints each key-value pair from `D`, separated by `#`.
Final Output:
HIMALAYA#8
ALPS#4
    
Was this answer helpful?
0

Top Questions on Miscellaneous