> For the complete documentation index, see [llms.txt](https://eduapps.gitbook.io/python-intro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://eduapps.gitbook.io/python-intro/5.-making-choices.md).

# 5. Making Choices

### `If...` statement

Sometimes your instructions require the computer to make choices based on certain conditions. In our example of coding a simple toy car, a condition in could be: **"If the car encounters an obstacle, then turn right"**

A simple "if..." condition in Python looks like this:

```python
if "hello" in "helloworld":
    print("it's in the string!")
```

\
In plain English, the above code says: **"If the string** **`hello`** **is contained in the string** **`helloworld`, then output** **`it's in the string!`"**&#x20;

Since the condition `"hello" in "helloworld"` is `True`, the next line`print("it's in the string!")` is executed.

### `If...else` statement

We can also introduce an `else:` to execute an alternate outcome (e.g. if the condition is not met)

```python
sister_age=15
brother_age=12
if sister_age > brother_age:
    print("sister is older!")
else:
    print("brother is older")
```

You can also use multiple comparisons in a single condition. For example, the following `if` statement finds out if the temperature is between the value 10 to 20, which is described by "larger than 10 **and** smaller than 20".

```python
temperature=15
if temperature>10 and temperature <20: 
	Print("nice!")
else:
	Print("Too extreme!")
```

### `If...elif...else` statement

We can create even more alternate outcome based on the different conditions:

```python
sister_age=15 	
brother_age=15
if sister_age>brother_age:
	print("Sister is older!")
elif sister_age==brother_age:
	print ("Same age.")
else	
	print ("Brother is older")
```

In fact, you can have as many `elif` conditions as you like. Note that in this case `else` statement is a "catch all" condition; if all the `elif` conditions are **NOT** met, then execute the `else` statement.
