30 Days of Code — Day 3

Tyler Carter
1 min readMar 8, 2021
Photo by Pankaj Patel on Unsplash

As a forcing function to get myself into the habit of writing these articles — I have decided to write an article for each day of the 30 Days of Code challenge from Hacker Rank.

The Task

Given an integer, n, perform the following conditional actions:

  • If n is odd, print Weird.
  • If n is even and in the inclusive range of 2 to 5 , print Not Weird.
  • If n is even and in the inclusive range of 6 to 20 , print Weird.
  • If nis even and greater than 20, print Not Weird.

Complete the stub code provided in your editor to print whether or not n is weird.

The Code

The Result

>? 3
… Weird
>? 24
… Not Weird
>? 18
… Weird

Conclusion

I actually overcomplicated this one. I was going to create a function to define what constituted ‘weird’ versus ‘not weird’. But I decided to keep it simple. While not the most elegant solution it was within the defined task and solved the problem.

Here is a link to the day_2 answer/challenge I wrote about previously: 30 Days of Code — Day 2

--

--

Tyler Carter
0 Followers

I am currently an Operations Program Manager for Microsoft. I have been teaching myself Python to use for Data Analytics and Machine Learning.