CBSE · 083Class XII · 2023Section D2 marks
Question 32(1or)
30 March 2023 · Computer Science (083)
Predict the output of the code given below :
python
def makenew(mystr):
newstr = ""
count = 0
for i in mystr:
if count % 2 != 0:
newstr = newstr + str(count)
else:
if i.lower():
newstr = newstr + i.upper()
else:
newstr = newstr + i
count += 1
print(newstr)
makenew("No@1")Answer
text
N1@3Explanation
Trace by character of "No@1": - count=0 (even): 'N' → upper → 'N'. newstr="N" - count=1 (odd): append str(1) → '1'. newstr="N1" - count=2 (even): '@'.lower() is truthy → upper → '@'. newstr="N1@" - count=3 (odd): append str(3) → '3'. newstr="N1@3"