I have an assignment in my Data Structures class and I am using Python to try to solve it. I am really stuck and rusty in Python so please bear with me.
Problem
Read a sentence from the console.
Break the sentence into words using the space character as a delimiter.
Iterate over each word, if the word is a numeric
value then print its value doubled, otherwise print out the word,
with each output on its own line.
Sample Run:
Sentence: Hello world, there are 3.5 items.
Output:
Hello
world,
there
are
7
items.
My Code so far...
import string
import re
def main():
string=input("Input a sentence: ")
wordList = re.sub("[^\w]", " ", string).split()
print("\n".join(wordList))
main()
This gives me this output:
>>>
Input a sentence: I like to eat 7 potatoes at a time
I
like
to
eat
7
potatoes
at
a
time
>>>
So my problem is figuring out how to extracting the numeric value and then doubling it. I have no clue where to even begin.
Any feedback is always appreciated. Thank you!