while loop walks through a word with an index. After it finds the letter a, it jumps two places ahead.
s = "aardvark"
i = 0
found = 0
while i < len(s):
if s[i] == "a":
found += 1
i += 2
else:
i += 1
print(found, i)
What is printed?Log in to join the discussion.
Loading…