🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Learning and Career with AI: all 10 questions

Quiz: Learning and Career with AI · Question 7 of 10

What does this print? (code)

What does this print?

def compress(s):
    if not s:
        return ""
    out, count = [], 1
    for prev, ch in zip(s, s[1:]):
        if ch == prev:
            count += 1
        else:
            out.append(f"{prev}{count}")
            count = 1
    out.append(f"{s[-1]}{count}")
    return "".join(out)

print(compress("zzzy"))
  1. A.z3y
  2. B.z3y1
  3. C.zzzy
  4. D.z2y1
Answer & explanation

Correct answer: z3y1

Three z's then one y.

Can you get the rest right without peeking?

Take the timed Quiz: Learning and Career with AI quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →