官术网_书友最值得收藏!

Finding a remainder – modulo

Modulo can seem like a strange concept. In fact, unless you are a programmer, it is likely that you have never heard of modulo. Modulo is a mathematical function that allows us to do a pision problem but only return the remainder. Why is this even useful? Why is it a good idea, and why should we care?

Usually, we want to know the entire answer to a pision problem—the quotient and the remainder. There are times, though, when we will only want to know the remainder of the pision problem. We will only care about what is leftover. Modulo is like a monster eating our dessert: we give the monster numbers to pide, and it just gives us leftovers.

While modulo is not especially useful in the world of school arithmetic, it can be very useful in moving objects in a game. So, it is good for us to build a modulo function and learn how modulo works.

To build a modulo function, you will need to get user input, just like all of the other functions you made. Then, you will call the modulo function. The symbol for modulo is % You can place the modulo operator where you would normally place the pision sign. Copy the following code in your Python shell as an example:

def modulo():
 first = int(raw_input('What is your first number?'))
 second = int(raw_input('What is your second number?'))
 print(first % second)

In the preceding screenshot, you can see how we added the modulo function to the other functions. If you still find modulo confusing, don't worry right away. Just know that it might come up as you are designing games, and you can check back here, as well as do an Internet, search to better understand modulo.

主站蜘蛛池模板: 通海县| 资溪县| 哈尔滨市| 和硕县| 威海市| 宜兴市| 鄂伦春自治旗| 淮安市| 广灵县| 手游| 万山特区| 焦作市| 隆子县| 湘阴县| 长沙市| 当雄县| 齐齐哈尔市| 勐海县| 天门市| 聂荣县| 马边| 博白县| 平顺县| 泰州市| 加查县| 区。| 呼和浩特市| 西安市| 分宜县| 勐海县| 甘肃省| 出国| 卓资县| 嘉荫县| 赣州市| 福安市| 博罗县| 常宁市| 宜兴市| 沈阳市| 育儿|