Skip to content
Question

Q.(a) Write the output of the following code : def Exam2026(given) : new=[] for ch in given[1:-1]: if ch.isupper(): new.reverse() elif ch not in new: new.append(ch) elif ch in new: new.pop() print(new) Exam2026("Gold-24Medals")

(OR)
(b) Write the output of the following code : def Exam2026(given): new = 0 while given: if new % 2: new += given % 10 else: new += given % 5 print(new, end='-') given //= 10 Exam2026(123456)
CBSECBSE Class XII Board 2026Subjective· 3mImportance★★★★★
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

Part (a): after trimming to "old-24Medal", the uppercase 'M' reverses the list and repeated 'd'/'l' pop the top, giving ['4', '2', '-', 'd', 'l', 'o']. Part (b): the digit-by-digit accumulation prints 1-6-10-13-15-16-.

Part (a)

The slice given[1:-1] removes the first and last character of "Gold-24Medals", leaving "old-24Medal". The loop checks, in order: if the character is uppercase reverse new; else if it is not already in new append it; else (it is already there) pop the last element.

charrulenew
oappend['o']
lappend['o','l']
dappend['o','l','d']
-append['o','l','d','-']
2append['o','l','d','-','2']
4append['o','l','d','-','2','4']
Muppercase -> reverse['4','2','-','d','l','o']
eappend['4','2','-','d','l','o','e']
dalready in -> pop['4','2','-','d','l','o']
aappend['4','2','-','d','l','o','a']
lalready in -> pop['4','2','-','d','l','o']

print(new) gives:

['4', '2', '-', 'd', 'l', 'o'] …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.