当第一个数字较小时,模运算如何工作? [英] How does a modulo operation work when the first number is smaller?

查看:63
本文介绍了当第一个数字较小时,模运算如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搞砸了python中的模运算,我知道它会吐出其余的东西.

I'm messing with the modulo operation in python and I understand that it will spit back what the remainder is.

但是如果第一个数字小于第二个数字怎么办?

But what if the first number is smaller than the second?

例如

2%5的答案是2.

这是怎么工作的?

2/5 = .4

推荐答案

此帮助

22  % 5 = 2 
17  % 5 = 2 
12  % 5 = 2 
7   % 5 = 2 
2   % 5 = 2

也许是

22 / 5 = 4 + 2/5
17 / 5 = 3 + 2/5
12 / 5 = 2 + 2/5
7  / 5 = 1 + 2/5
2  / 5 = 0 + 2/5

这篇关于当第一个数字较小时,模运算如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆