22find Fix Errors Syntax Logic Following Code Snippets Function Returns String Containing Q37031731

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

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.