[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Please /g/ help me comprehend num = input("Enter a number:

You are currently reading a thread in /g/ - Technology

Thread replies: 6
Thread images: 1
File: FUPx_g.jpg (59 KB, 414x610) Image search: [Google]
FUPx_g.jpg
59 KB, 414x610
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)
Thread replies: 6
Thread images: 1

[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
If a post contains illegal content, please click on its [Report] button and follow the instructions.
This is a 4chan archive - all of the content originated from them. If you need information for a Poster - you need to contact them.
This website shows only archived content and is not affiliated with 4chan in any way.
If you like this website please support us by donating with Bitcoin at 1XVgDnu36zCj97gLdeSwHMdiJaBkqhtMK