Advertisement
timber101

Word Reversed

Dec 12th, 2020
664
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None
  1. """
  2. Create a function that accepts a string and returns the same string reversed.
  3. """
  4. #  I know this can be done with slicing that can do this, but will develop two ways
  5.  
  6. def fnrevword():  # looping method
  7.     revword= ""
  8.     for i in range(len(tgtword)-1,-1,-1):
  9.         revword = revword + tgtword[i]
  10.     print(revword + " using fnrevword")
  11.    
  12. def slcrevword(): # slicing
  13.     revwrd2=tgtword[len(tgtword)::-1]
  14.     print(revwrd2 + " using slcrevword")
  15.  
  16. tgtword = input("Please enter a word > ")
  17.  
  18.  
  19. # call on the functions
  20. fnrevword()
  21. slcrevword()
  22.  
Advertisement
RAW Paste Data Copied
Advertisement