22.Find and fix the errors (syntax or logic) in the followingcode snippets: # this function returns a string containing everyother letter in # word
def everyOther(word):
final = “”
for i in range(word):
if i % 2 == 0:
final = word[i]
return final
def main(): everyOther(“grapefruit”)
print(final)
main()
Answer
CODE:
def everyOther(word): # changed the type of final to list final = [] # run the loop to the length of the word for i in range(len(word)): if i % 2 == 0:
OR
OR