Back to Lessons
BeginnerBasics
Variables and Numbers
lesson_02.py
>>> ## Concept
Variables in Python are used to store information that you want to reuse later in your program. Think of a variable as a container that holds data, like a labeled jar. You can store numbers in variables to make calculations easier and to make your code more readable.
### Creating Variables
To create a variable, assign a value to it using the `=` sign.
```python
number = 10
```
Here, we created a variable named `number`, and it holds the value `10`.
### Using Variables in Calculations
Variables can be used to perform mathematical operations.
```python
x = 5
y = 3
result = x + y
print(result) # Output: 8
```
In this example, `x` holds the value `5` and `y` holds `3`. We add them together and store the result in a new variable called `result`.
### Updating Variable Values
You can update the values stored in variables.
```python
score = 20
score = score + 5
print(score) # Output: 25
```
Initially, `score` is `20`, and we update it by adding `5` to assign the new value `25`.
## Practice
Now it’s your turn to create and use a variable. Follow these steps to complete the task:
1. **Create a variable** called `score`.
2. **Assign it** a value of `100`.
3. **Print** the value of `score`.
Here is the basic format you should use in your code:
```python
score = 100
print(score)
```
Modify the starter code to include the lines above. Once done, test your code to ensure it prints `100`, as expected in the test case. This verifies that you have successfully stored and printed the number using a variable.
Code Editor
Sign in to submit your answer and earn XP.