Counting and Keeping Track with Edward
Learn about arithmetic operators and data types in Python.
With the ability to memorize, Edward can now tell whether or not he has already potted a plant or removed trash.
What if Edward could also count the number of tasks he performed, like the number of plants he has potted or the number of moves he has made? This could help Edward make elaborate plans and keep track of his progress. With this ability to count, we can even add more features to Edward, such as the amount of energy he consumes.
Counting the placed plants
The ability to count would be a great enhancement for Edward. Let’s interact with the widget below. Edward can now count the number of plants he has placed. What’s more interesting is that his energy reduces with each step he takes. He loses 3% for each move, 5% for when he places a plant, and 1% for each turn.
All of this is possible due to mathematical operations such as addition and subtraction.
These basic mathematical operations are fundamental in programming and are used in various contexts to manipulate data and perform mathematical calculations.
Mathematical calculation in Python
In Python, we use arithmetic operators to perform these calculations. These operators work just like when you solve simple math problems. For example, the +
symbol adds numbers together, -
subtracts them, *
multiplies them, and /
divides them.
Arithmetic Operator | Operation | Example |
| Addition | 10 + 5 results in 15 |
| Subtraction | 10 - 5 results in 5 |
| Multiplication | 10 * 5 results in 50 |
| Division | 10 / 5 results in 2 |
Adding two numbers
Let’s see how to add two numbers in Python. This should be easy: create two variables to store the numbers we want to add, compute their ...