Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #function to reverse text
- def rev(text):
- revText = "" #take empty string
- #add each char in front
- for c in text:
- revText = c + revText
- return revText #return reversed string
- #main
- if __name__ == "__main__":
- print("Welcome to Digit Flipper")
- s = input("Enter Some Text:\n") #get input
- nums = "0123456789" #digits
- text = "" #take an empty string
- print("Revised String:")
- #loop through input string
- for c in s:
- #if digit
- if c in nums:
- text = text + c #add it to text
- else: #otherwise
- print(rev(text),end='') #print reversed text
- text = "" #make text empty
- print(c,end='') #print char
- print(rev(text)) #print if any text left
- OUTPUT:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement