DEV Community

Cover image for Day 3: Intro To Conditional Statments - 30 Days of Code HackerRank
Aayushi Sharma
Aayushi Sharma

Posted on • Edited on • Originally published at codeperfectplus.com

Day 3: Intro To Conditional Statments - 30 Days of Code HackerRank

Image description

Conditional Statements

Conditional statements are condition that allow to execute a block of code if certain conditions are meet. IF/Elif/Else are one type of conditional statement.

In this problem we will print Weird/Not Weird based on number provided by the user.

Task

Given an integer, , perform the following conditional actions:

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

Conditional Statement Solution Hackerrank Solution In Python

if __name__ == "__main__":
    N = int(input())
    if N % 2 != 0:
        print("Weird")
    elif 2 < N < 5:
        print("Not Weird")
    elif 6 < N <= 20:
        print("Weird")
    elif N > 20:
        print("Not Weird")
Enter fullscreen mode Exit fullscreen mode

Conditional Statement Solution Hackerrank Solution In JavaScript(Js)

function main() {
    const N = parseInt(readLine(), 10);
    if (N % 2 != 0) {
        console.log('Weird')
    } else if (N > 20) {
        console.log('Not Weird')
    } else if (N >= 6) {
        console.log('Weird')
    } else if (N >= 2) {
        console.log('Not Weird')
    }
}
Enter fullscreen mode Exit fullscreen mode

Check out 30 Days of Code| CodePerfectplus for All solutions from this series.

Top comments (0)