You are browsing as a guest. Sign up (or log in) to start making projects!

1h 12m 45s logged

Now I’m working more with functions here. I made two simple ones that take three numbers as parameters and return the sum, and another that checks if the number passed as a parameter (int) is even.
I had almost everything right, but I looked at it and thought "man, there's a way to improve/make this shorter", so I sent it to *AI Mode on Chrome (I use it because it's much more integrated with search engines, can see websites, docs, stuff like that, forums, etc) and it gave me this which I thought was pretty cool:

return num % 2 == 0

The result of this is a boolean value, and when printing you just need to check the value of the variable which is already True or False, and that’s it. Pretty cool…I had already done an exercise in C to check if something is a palindrome in my course. There, the code gets longer (verbose, from what they say) because you have to use strings which are arrays, validate all those things. I don’t know, but quickly thinking about the logic and the use of variables for comparing letters, it seemed more intuitive there… Here I haven’t done it with a function yet. I’ll do it soon. Afterwards, to check what I had done up to that point, I sent it in Chrome and it just gave me a crazy trick! There are methods/arguments used in string slicing that reverse the string and check if it’s a palindrome in just 5 lines of code… I really didn’t know that.

0
3

Comments 0

No comments yet. Be the first!