Help me please with the code

I write a code for my study project.
The task is finding in a text some words and change the text. Example:
“This is so exciting (up, 2)” → “This is SO EXCITING”
or I SHOULD STOP SHOUTING (low, 3)" → “I should stop shouting”
I already wrote a code that changes a text without numbers -
“I should stop SHOUTING (low)” → “I should stop shouting”
But I need to write it with using numbers too like in examples above.
Please help me.
That part of my code