Answer:
# the function fix_yz is defined
# it takes a string as parameter
def fix_yz(word):
# new_word is to hold the new corrected string
new_word = ""
# loop through the string
# and check for any instance of y or z.
# if any instance is found, it is replaced accordingly
for each_letter in word:
if each_letter == 'z':
new_word += 'y'
elif each_letter == 'Z':
new_word += 'Y'
elif each_letter == 'y':
new_word += 'z'
elif each_letter == 'Y':
new_word += 'Z'
else:
new_word += each_letter
# the value of new string is returned
return new_word
Step-by-step explanation:
The function is written in Python 3 and it is well commented. An image is attached showing the output of the given example.
The function take a string as input. It then loop through the string and check for any instance of 'y' or 'z'; if any instance is found it is swapped accordingly and then append to the new_word.
The value of bew_word is returned after the loop.