# Exercise - Convert strings to numbers and use absolute values

## Create an application to work with numbers and user input

You'll frequently need to convert string values into numbers to properly perform different operations, or determine the absolute value of a number. In this exercise, you will create a project to calculate the distance between two planets based on user input.

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.

## Read the values from user

To create our application, we want to read the distance from the sun for two planets, and then display the distance between the planets. We'll do this by using `input` to read the values, `int` to convert to integer, and then `abs` to convert the result into its absolute value.&#x20;

Your code should resemble the following

{% code overflow="wrap" %}

```python
first_planet_input = input('Enter the distance from the sun for the first planet in km')
second_planet_input = input('Enter the distance from the sun for the second planet in km')
```

{% endcode %}

## Convert to number

Because `inpu`t returns string values, we need to convert them to numbers. Add the code to convert each input into an integer using `int` Store the values in `first_planet` and `second_planet` respectively.

Your code should resemble the following:

```python
first_planet = int(first_planet_input)
sencond_planet = int(second_planet_input)
```

## Perform the calculation and convert to absolute value

With your values stored as numbers, you can now add the code to perform the calculation, subtracting the first planet from the second. Because the second planet might be a greater number, you'll use `abs` to convert it to an absolute value.

Subtract `first_planet` from `second_planet` and convert the result to its absolute value by using `abs`. Store the result in a variable named `distance_km`. Then display the result on the screen.

Your code should resemble the following:

```python
distance_km = second_planet - first_planet
print(abs(distance_km))
```

## Test your application

To test your project, run the notebook. You'll be prompted in a dialog to provide the distances. You can use the ones from the following table:

| Planet  | Distance from sun |
| ------- | ----------------- |
| Mercury | 57900000          |
| Venus   | 108200000         |
| Earth   | 149600000         |
| Mars    | 227900000         |
| Jupiter | 778600000         |
| Saturn  | 1433500000        |
| Uranus  | 2872500000        |
| Neptune | 4495100000        |


---

# 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-4-use-mathematical-operations-in-python/exercise-convert-strings-to-numbers-and-use-absolute-values.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.
