← 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"))
- A.z3y
- B.z3y1
- C.zzzy
- 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 →