# Task 9: Replace the space character Write a Python program to replace the space character that occurs after a word ending with a or r with a newline character. Sample data : 'area not a a2\_b roar took 22' Sample output : area not a a2\_b roar took 22
时间: 2023-07-02 16:11:03 浏览: 135
A GARCH option pricing model with α-stable innovations
Here's the Python code to achieve the desired output:
```python
data = 'area not a a2_b roar took 22'
output = ''
i = 0
while i < len(data):
if data[i] == ' ' and (i > 0 and (data[i-1] == 'a' or data[i-1] == 'r')):
output += '\n'
else:
output += data[i]
i += 1
print(output)
```
Output:
```
area not a a2_b roar took 22
```
阅读全文