Codewars Review for Gaining Code Experience

Since I had last posted about Codewars I have been spending more time trying out the challenges, and I realize now how valuable it is a tool to develop your coding skills.

The last challenge I did required for me to create a function that would evaluate value x and return certain words based on whether the number is divisible by 3, 5, 3 and 5, or neither. I knew how to evaluate whether a number can be divisible by another by determining whether there is a remainder (using %), and I knew how to do if, elif, and else statements, so I put those to work in my code and get a working program.

def multiple(x):
    if x % 3 == 0 and x % 5 == 0:
        return "BangBoom"
    elif x % 3 == 0:
        return "Bang"
    elif x % 5 == 0:
        return "Boom"
    else:
        return "Miss"

After you submit a working code you are sent to a page that lists the submitted code from other users. By default the code is listed by user evaluations, with the codes rated “best practices” at the top of the list. Besides having to call upon my coding knowledge to complete their challenge, this is my favorite feature of Codewars. I love that I can compare my work with work of others and learn how to make my code more effective and streamlined. The top rated code for this challenge was:

def multiple(x):
    return 'Bang' * (x % 3 == 0) + 'Boom' * (x % 5 == 0) or 'Miss'

This code condenses my 8 lines in the function into just one. I didn’t know how to do that before, and now I do! For now I am trying to just get through the challenges without giving up, but eventually I hope that I can make posts that are also well written. I’m very excited to use it as a tool!!

Read More Post