Introduction to Strings Quiz Question help

Hi guys. I am struggling with understanding this code. How is the i % 2 ==0 print out even indexs? I feel I am struggling with what I is for. I would appreciate any help, i just want to understand and learn. Thank you!

def print_some_characters(word):
for i in range(len(word)):
if i % 2 == 0:
print(word[i])

print_some_characters(“watermelon”)

Because the index is, i, and it has even parity (divisible by 2).


Does your output look like this?

w
t
r
e
o
2 Likes

Hello!

Yes my output is
w
t
r
e
o

It prints out all even indexes. I am confused on why it is doing that? I think my confusion is coming around the i and how it produces only even indexes? Thank you!

1 Like

if i % 2 == 0 means if i divided by 2 has no remainders… which is the same as saying if i is even
it sounds like youre just confused on how % works

Yea I understand it now. Thanks!

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.