# Tutorial 4 - Problem 1 # # Write a function that takes a string as a parameter # and displays the letters backward, one per line. # # Anne Lavergne # Dec. 2015 def printBackward(aString): for index in range(len(aString)-1, -1, -1): print(aString[index]) return # Then, write another function that takes a string as a parameter and # returns the string reversed (without printing it). def reverse1(aString): reversedString = "" for index in range(len(aString)-1, -1, -1): reversedString += aString[index] return reversedString def reverse2(aString): reversedString = aString[ : : -1] return reversedString # Main print('Calling printBackward("Fantastic!")') printBackward("Fantastic!") print('Calling reverse1("Fantastic!") and result is: %s' %(reverse1("Fantastic!"))) print('Calling reverse2("Fantastic!") and result is: %s' %(reverse2("Fantastic!")))