Closed iHiD closed 6 months ago
I will have to instruction append on this because %
, math.remainder()
and math.fmod()
do not always return the same thing in Python.
>>> remainder(20, 3)
Out[52]: -1.0
>>> fmod(20, 3)
Out[53]: 2.0
>>> 20 % 3
Out[54]: 2
Also, using remainder
and fmod
require an import, the operator does not. ๐คท๐ฝโโ๏ธ
@BethanyG Cool, thanks. I guess it's worth noting that math.remainder
is very much not what an average person would expect and telling them just to use %
? Or maybe just say "The modulo operator in Python is %
"?
The reference to modulo/remainder hasn't really changed in this PR other than we stop telling peopleย that %
means modulo, which it doesn't in most languages (e.g. Python and JavaScript being the two biggest beginner languages, and two languages where %
doesn't mean modulo)
Python and JavaScript being the two biggest beginner languages, and two languages where
%
doesn't mean modulo
err. %
DOES mean modulo in Python. But yes, agree that we need to make sure Pythonistas understand the difference between the three. ๐
I will PR at some point PST today.
As far as I know is the biggest languages where %
isnt modulo is Swift and javascript.
But both in Swift and Crystal isn't %
(modulo or remainder in this case) not the easiest and exemplary way to check divisibility. In Swift is it because the %
is an actual remainder operator and can create some situations which another method avoids.
err. % DOES mean modulo in Python. But yes, agree that we need to make sure Pythonistas understand the difference between the three. ๐
ChatGPT lies again! ๐
I think we can safely say that %
is ok for raindrops in any language that supports it, regardless of whether it's modulo or remainder?
Yeah, I mean as long as the exercise doesn't deal with signed integers so do all languages I know work the same with the %
operator.
I think we can safely say that
%
is ok for raindrops in any language that supports it, regardless of whether it's modulo or remainder?
Modulo and remainder differ only when the dividend and the divisor differ in sign. So in particular when both operands are nonnegative the modulo and remainder are the same.
5 `rem` 3 = 2 5 `mod` 3 = 2
5 `rem` -3 = 2 5 `mod` -3 = -1
-5 `rem` 3 = -2 -5 `mod` 3 = 1
-5 `rem` -3 = -2 -5 `mod` -3 = -2
err. % DOES mean modulo in Python. But yes, agree that we need to make sure Pythonistas understand the difference between the three. ๐
ChatGPT lies again! ๐
In powershell depend on the context and placement, %
could mean modulus or act as alias for foreach-object
.
5 % 2
=> 1
or
@(1,2,3,4,5) | % { $_ % 2 }
=> @(1,0,1,0,1)
Generally I recommend using the fullname to avoid any possible confusion, and easier to read but this practice is still quite prevalent among more experienced user when they script in terminal. This shouldn't be much of an issue regarding this exercise I suppose.
Prepares Raindrops for #48in24.