Skip to content
Question

Q.(a) Predict the output of the following code :
def ExamOn(mystr) :  
    newstr = ""  
    count = 0  
    for i in mystr:  
        if count%2 != 0:  
            newstr = newstr + str(count-1)  
        else:  
            newstr = newstr + i.lower()  
        count += 1  
    newstr = newstr + mystr[:2]  
    print("The new string is:", newstr)  
ExamOn("GenX")  

(OR)
(b) Write the output on execution of the following Python code:
def Change(X):  
    for K,V in X.items():  
        L1.append(K)  
        L2.append(V)  
D={1:"ONE",2:"TWO",3:"THREE"}  
L1=[]  
L2=[]  
Change(D)  
print(L1)  
print(L2)  
print(D)  
CBSECBSE Class XII Board 2025Subjective· 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) -> The new string is: g0n2Ge

Part (b) -> [1, 2, 3] / ['ONE', 'TWO', 'THREE'] / {1: 'ONE', 2: 'TWO', 3: 'THREE'}

Part (a)

ExamOn builds newstr character by character. count starts at 0 and increases by 1 each pass. The test count % 2 != 0 is True for odd count and False for even count.

  • On even count -> else branch adds the current character in lowercase.
  • On odd count -> adds str(count-1), i.e. the previous index as text.

Tracing "GenX":

  • 'G', count=0 (even) -> add 'g' -> "g"
  • 'e', count=1 (odd) -> add str(0) -> "g0"
  • 'n', count=2 (even) -> add 'n' -> "g0n"
  • 'X', count=3 (odd) -> add str(2) -> "g0n2"

After the loop, mystr[:2] = "Ge" is appended -> "g0n2Ge".

Expected output:

The new string is: g0n2Ge …

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.