Working with Numbers
Learn about how can we use numbers in computer programs.
We'll cover the following
The importance of numbers
Numbers are essential in computer programs. We use them to represent real-world concepts, such as the number of items in a shopping cart, the weight of a package, and the distance to a location. We also use them to represent internal things within our program, such as the number of characters in a name, so that we can calculate whether it will fit on an address label if we print it. The point is, we use numbers all the time, so let’s see what we can do with them.
Performing arithmetic operations
First, we can do basic arithmetic, such as addition, subtraction, and division, as in the following code snippet:
Note: The output of the code below will be an integer because integer division is taking place.
Get hands-on with 1400+ tech skills courses.