this post was submitted on 21 Jun 2023
21 points (86.2% liked)

Programmer Humor

32497 readers
495 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] Guy_Fieris_Hair@lemmy.world 0 points 1 year ago* (last edited 1 year ago) (1 children)

I feel like I accidentally do something similar everytime I program anything. I am just bad at it, I don't know the short cuts or all the commands, but by God, it will work when I am done with it... maybe.

I don't know the right wat to do this, but I think there would be something like:

x = Number

If (x//2)is.integer() == "true":

Print("Even")

Else:

Print("odd")

Maybe? Idk. Probably a bunch of syntax issues and I haven't written anything in like a year.

[–] nero@lemmy.world 0 points 1 year ago (1 children)

You basically got it yeah. You can do x % 2 and check if that is 0, as % calculates the remainder (in python at least)

[–] Guy_Fieris_Hair@lemmy.world 1 points 1 year ago* (last edited 1 year ago) (2 children)

y = 1

while y ==1:

x = input("Enter Number")

if int(x) % 2 == 0:

print("EVEN")

else:

print("ODD")

I don't know why, but I opened up my IDLE for the first time in a year and did it.

[–] nero@lemmy.world 1 points 1 year ago (1 children)

Know you probably don’t care, but you can do a while loop using while True:

Which is the same as you using a statement which equals to true.

Thought i don’t think you need it for what you’re doing currently.

[–] nero@lemmy.world 1 points 1 year ago

Unless you want it to keep asking the question of course**

[–] MrMagnesium12@feddit.de 1 points 1 year ago
int val = 3;
bool is_odd = val & (decltype(val))0x01 == (decltype (val))1;