Post

Pavel Oliva 🔶
Pavel Oliva 🔶@Pavel_Oliva·
@CodeRed_dev There is. If you rename number variable to n, you can save a lot of time typing all of this 😂
English
0
0
3
474
Lyuris420
Lyuris420@J0k3r00957081·
@CodeRed_dev You can, in fact, just do a function for this! So cool! 😀
Lyuris420 tweet media
English
6
0
56
2.1K
SHADOWKI56
SHADOWKI56@Patrickrogan731·
@CodeRed_dev I remember showing a classmate the easier trick, for our assignment, and she looked at me like i was a wizard😅
English
0
0
7
571
Audio Bellum🇬🇧🇯🇲
Audio Bellum🇬🇧🇯🇲@AudioBellum·
@CodeRed_dev If the number leave a remainder when divided( or is an odd number), return false. Otherwise, return true. I could be wrong but, that's the pattern I'm seeing.
English
1
0
4
985
Raphytator
Raphytator@Raphytator·
@CodeRed_dev Use a modulo to know if the number is odd or not : if (number % 2 == 0) return true; else return false;
English
2
0
1
164
Digital Emergence LTD
Digital Emergence LTD@digitalEmergenc·
@CodeRed_dev I am guessing that is clickbait… definitely getting views 🤣 Anyway. Return (number % 2 ) == 0;
English
1
0
1
934
Change Machine Labs
Change Machine Labs@ChangeMachines·
@CodeRed_dev def isOdd(x): return True if x % 2 else False def isEven( x ) return False if x % 2 else True
English
0
0
0
439
iNightfall
iNightfall@iNightfaller·
@CodeRed_dev Just you wait and see what happens if the number is zero 😏
English
0
0
0
136
ashtonkase
ashtonkase@stonekase·
@CodeRed_dev Do “ if(number % 2 == 0) return true; else return false;
English
0
0
0
22
Pagefile
Pagefile@Pagefile0x00·
@CodeRed_dev You can put all the comparisons for even in one if with || and then the else is odd because obviously you've just tested all the evens. It'll probably save you a bit on typing that way
English
0
0
0
41
Ivan Gusev
Ivan Gusev@piafraus·
@CodeRed_dev Programming is all about noticing interesting properties, here is how you can make the code much better: return str(number)[-1] in '02468'
English
0
0
0
83
sameer
sameer@phee3D·
@CodeRed_dev the good thing is you only have to do this once for all possible numbers and then export it as an npm package that you can install in every single project of yours
English
0
0
0
32
Paylaş