Question
Write a program that reads text from the user and reverses the order of every number that appears in the text. For example: Hello! The
Write a program that reads text from the user and reverses the order of every number that appears in the text. For example: Hello! The number is 17. will become Hello! The number is 71. To help with this problem, first write a function rev(text) that takes a string of text and returns the reverse. For example, rev("Oranges") would return "segnarO". You may create any additional function you need. You must create the rev function. Your program will ask for a string of text and reverse and number. A number is defined as any sequence of digits 0-9. Remember to use if name=="__main": so that ZyBooks can test your rev function. Here are two examples.
This is the code I have so far but this reverses the entire input instead of reversing only numbers:
print('Welcome to Digit Flipper') text = input('Enter Some Text: ') print('Revised String:') for char in range(len(text) - 1, -1, -1): print(text[char], end="")
Welcome to Digit Flipper Enter Some Text: Hello! The number is 17 Revised String: Hello! The number is 71Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started