Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Create a function that accepts a string and returns the same string reversed.
- """
- # I know this can be done with slicing that can do this, but will develop two ways
- def fnrevword(): # looping method
- revword= ""
- for i in range(len(tgtword)-1,-1,-1):
- revword = revword + tgtword[i]
- print(revword + " using fnrevword")
- def slcrevword(): # slicing
- revwrd2=tgtword[len(tgtword)::-1]
- print(revwrd2 + " using slcrevword")
- tgtword = input("Please enter a word > ")
- # call on the functions
- fnrevword()
- slcrevword()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement