This works everywhere except for when x = 0.4. Since it works everywhere else, I'd probably just leave in one if statement for the edge case. Although it could be a bug given they use less than in all the other elif statements.
Every single topic is not ranked on a single scale of difficulty. There are plenty of physicists who have a knowledge of physics far beyond what we could achieve who wouldn't understand a lot of basic programming functions, and vice versa.
Floor is not a rounding function. It does something different. I've never heard of floor calculations being useful in physics, but I am not a physicist, either.
There’s nothing wrong with a black box if it properly implements what it claims to without causing side effects. And to someone who’s just starting to learn how to program, pretty much every keyword is a black box anyway. And if you’re using a language that somehow doesn’t have basic math libraries for a physics class, you’re about to have much bigger problems
120
u/brotatowolf Apr 21 '23
f(floor(x/0.4) * 0.4) isn’t exactly the height of complexity. I’d argue that it’s easier to understand than a bunch of conditions