Back to Lessons
BeginnerBasics
Simple Math Operations in Python
lesson_03.py
>>> ## Concept
Python can perform math calculations just like a simple calculator. It allows you to add, subtract, multiply, and divide numbers using operators. Here's a quick look at how you can perform these basic operations:
### Addition (+)
This operator adds two numbers together:
```python
result = 10 + 5
print(result) # This will output: 15
```
### Subtraction (-)
This operator subtracts one number from another:
```python
result = 20 - 7
print(result) # This will output: 13
```
### Multiplication (*)
Use the asterisk to multiply two numbers:
```python
result = 6 * 4
print(result) # This will output: 24
```
### Division (/)
Use the slash to divide one number by another:
```python
result = 15 / 3
print(result) # This will output: 5.0
```
You can also combine different operations, but remember the order of operations: multiplication and division come before addition and subtraction, unless you use parentheses to change the order.
## Practice
**Your task:** Calculate **25 + 17** and print the result.
- **Steps to follow:**
1. You need to add the numbers 25 and 17.
2. You can either store the result in a variable and then print it, or you can print the result directly without using a variable.
3. Ensure your output is exactly **42**!
**Example ways to write the solution:**
- **Directly print the result:**
```python
print(25 + 17)
```
- **Use a variable to store the result, then print it:**
```python
result = 25 + 17
print(result)
```
Try it out! Make sure the output shows 42 when you run the code.
Code Editor
Sign in to submit your answer and earn XP.