Advertisement
Guest User

Untitled

a guest
Mar 18th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #function to reverse text
  2.  
  3. def rev(text):
  4.  
  5. revText = "" #take empty string
  6.  
  7. #add each char in front
  8.  
  9. for c in text:
  10.  
  11. revText = c + revText
  12.  
  13. return revText #return reversed string
  14.  
  15. #main
  16.  
  17. if __name__ == "__main__":
  18.  
  19. print("Welcome to Digit Flipper")
  20.  
  21. s = input("Enter Some Text:\n") #get input
  22.  
  23. nums = "0123456789" #digits
  24.  
  25. text = "" #take an empty string
  26.  
  27. print("Revised String:")
  28.  
  29. #loop through input string
  30.  
  31. for c in s:
  32.  
  33. #if digit
  34.  
  35. if c in nums:
  36.  
  37. text = text + c #add it to text
  38.  
  39. else: #otherwise
  40.  
  41. print(rev(text),end='') #print reversed text
  42.  
  43. text = "" #make text empty
  44.  
  45. print(c,end='') #print char
  46.  
  47. print(rev(text)) #print if any text left
  48.  
  49. OUTPUT:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement