How To Know If A Number Is Odd

I don’t actually have a problem, I’m asking this because I’m courious

1 Like

You can take the modulo of a number, which provides its remainder, if the remainder of % 2 is 0, than your number is even, here is a quick example:
number = 5

if number % 2 != 0:
print(“The number is odd”)
else:
print(“The number is even”)

3 Likes

That doesn’t work, I get either 0.02 (1) or 0.04 (2)

Not to mention the many syntax errors. Looks like it was written in C#

In Lua, it would be like this

local number = 5

if number % 2 ~= 0 then
	print("The number is odd")
else
	print("The number is even")
end

And yes, it does actually work

Strangely this is what I get;

Also the code seemed strange, now I know it’s in C#

When it runs, however:


I don’t know what I’m doing wrong, also thanks for the solution!
Also, it gives me the result when I type 5%2 in the search bar, but not in the calculator, Google is broken…

Google calculator’s issue is that it multiplies it by two for some reason, no matter what you do. Bing’s calculator and the TI-84 I have in my backpack work normally lol

You are calculating 5 percent times 2, which result in 10 percent, or 0.1.

You are suppose to type 5 % 2.

image

I think you mean checking if its a number right?

Based on the topic title and description, no.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.