Please /g/ help me comprehend
num = input("Enter a number: ")
mod = int(num) % 2
if mod > 0:
print("You picked an odd number.")
else:
print("You picked an even number.")
^^^^^^^^^^^^^^^^^^^^^
Why Is It that the number chosen through input divided by 2 has to be greater than 0 to be considered an odd number. 8 divided by 2 Is four, which Is an even number. Could someone explain why this Is?
>>55611426
Tis Python btw.
>>55611426
Google modulus
>>55611439
Holy shit. The remainder Is key. Fucking shit I'm stupid.
>>55611426
It is not input divided by 2. It's input MODULO 2. Modulo (or mod) is the remainder from division.
Any even number divided by 2 will have a remainder of 0.
Any odd number divided by 2 will have a remainder of 1.
So in your example, 8%2 = 0 (8/2=4 Reminder = 0)
But 7%2 =1 ( 7/2 = 3 Reminder = 1)