PyLearn / Multiply & Divide



Welcome to PyLearn once again! In this tutorial I’m going to show you ho to multiply and divide to numbers in Python. In the previous tutorial I had shown how to add and subtract numbers in Python. So let’s get started.

Suppose you are programming a racing game. Now you want to design it in such a way that the speed of the car, increases on kicking the gas pedal and decreases on applying the brakes, at a constant rate. You would need to multiply the speed of the car with some number, say x, and divide it with another number, say y, for decreasing it’s speed on applying the brakes. You can easily perform the multiplication and division of fairly large numbers easily in Python. Two examples of multiplication and division are given below:



print (2 * 2)

Output: 4



print (2 / 2)

Output: 1



The programs given above are pretty simple. I have not included large numbers for the sake of simplicity. The first program multiplies 2 with 2 and thus, we get the output as 4 which is the product of 2 and 2. the second one does a similar work the only difference is that instead of multiplying, it divides the numbers and hence, we get the output as 1. There are two operators in work in the given programs. The first one is the multiplication operator “*and the second one is the division operator “/”. These operators simply multiply and divide the numbers arithmetically. There are yet other arithmetic operators in Python whose functions I will explain in the tutorials to come.

In the next lesson I would explain how to perform calculations like addition and subtraction in Python. Thanks!



Next Lesson:


Previous Lesson: