1
2
3
4
5
6
7
8
9
| class Solution:
def discountPrices(self, sentence: str, discount: int) -> str:
words = sentence.split()
for i, word in enumerate(words):
if word.startswith('$') and word[1:].isdigit():
price = int(word[1:])
discounted_price = price * (100 - discount) / 100
words[i] = "${:.2f}".format(discounted_price)
return ' '.join(words)
|