# Exercise: Transform strings

There are several operations you can perform on strings when you manipulate them. In this exercise, you'll use string methods to modify text with facts about the Moon and then extract information to create a short summary.

This exercise is broken into a series of steps. For each step you will be presented with the goal for the step, followed by an empty cell. Enter your Python into the cell and run it. The solution for each step will follow each cell.&#x20;

## Parsing interesting facts about the moon

Start by storing the following paragraph in a variable named `text`:

{% code overflow="wrap" %}

```
Interesting facts about the Moon. The Moon is Earth's only satellite. There are several interesting facts about the Moon and how it affects life here on Earth. On average, the Moon moves 4cm away from the Earth every year. This yearly drift is not significant enough to cause immediate effects on Earth. The highest daylight temperature of the Moon is 127 C.
```

{% endcode %}

Your code should resemble the following:

{% code overflow="wrap" %}

```python
text = """Interesting facts about the Moon. The Moon is Earth's only satellite. There are several interesting facts about the Moon and how it affects life here on Earth. On average, the Moon moves 4cm away from the Earth every year. This yearly drift is not significant enough to cause immediate effects on Earth. The highest daylight temperature of the Moon is 127 C."""
```

{% endcode %}

## Separate the paragraph into sentences

In English each sentence ends with a period. You will use this to break the paragraph into difference sentences. Using the `split` method to split the text into sentences by looking for the string `.` (a period followed by a space). Store the result in a variable named sentences. Print the result.

```python
sentences = text.split('.')
print(sentences)
```

## Desired output

When you run the cell you should see the following result:

{% code overflow="wrap" %}

```
['Interesting facts about the Moon', " The Moon is Earth's only satellite", ' There are several interesting facts about the Moon and how it affects life here on Earth', ' On average, the Moon moves 4cm away from the Earth every year', ' This yearly drift is not significant enough to cause immediate effects on Earth', ' The highest daylight temperature of the Moon is 127 C', '']
```

{% endcode %}

## Find keywords

You will finish your program by adding the code to find any sentences which mention temperature. Add code to loop through the `sentences` variable. For each sentence, search for the word temperature. If the word is found, print the sentence.

Your code should resemble the following:

```python
for sentence in sentences:
    if 'temperature' in sentence:
        print(sentence)
```

## Desired output

When run, the output should look like the following

```
The highest daylight temperature of the Moon is 127 C.
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://learn.pqtkha.com/programming/technology/python/microsoft-training-python-for-beginners/module-3-use-strings-in-python/exercise-transform-strings-1.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
