CODE CHALLENGE: STRING METHODS
Guys, may I ask why in this exercise, even though I define the location of “i” in word must be able to divide 2 without any remainder ==> the output for the second string “Hello World!” is still Hlloworld, in which the second “l” location happens to be word, which is not satisfied the if condition?.
Could someone please help me to understand this? Thanks a million times
Every Other Letter
Create a function named
every_other_letter that takes a string named
word as a parameter. The function should return a string containing every other letter in
wordcollection = " "
for i in word:
if word.find(i) % 2 == 0: wordcollection += i elif word.find(i) % 2 != 0: continue elif word == "": return wordcollection == ""