Skip to content
Programming101
Programming101

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programming101

Learn everything about programming

Hackerrank Day 3 intro to conditional statements solution

YASH PAL, 31 July 2024

In this HackerRank Day 3 intro to the conditional statements problem, we need to develop a program that can accept an integer as an input. and if the number is odd then print Wierd and if not then print not Wierd.

Day 3 intro to conditional statements hackerrank solution

Problem solution in Python 2 programming.

#!/bin/python

import sys


n = int(raw_input().strip())
if n & 1:
    print "Weird"
elif n >= 2 and n <= 5:
    print "Not Weird"
elif n >= 6 and n <= 20:
    print "Weird"
elif n > 20:
    print "Not Weird"

Problem solution in Python 3 programming.

#!/bin/python3

import math
import os
import random
import re
import sys



if __name__ == '__main__':
    N = int(input())

    if N%2 != 0:
        print("Weird")
    else:
        if N>=2 and N<5:
            print("Not Weird")
    
        if N>=6 and N<=20:
            print("Weird")
    
        if N>20:
            print("Not Weird")

Problem solution in java programming.

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
   
    public static void main(String[] args) {
       Scanner sc=new Scanner(System.in);
       int n=sc.nextInt();            
       String ans="";
       if(n%2==1){
           ans = "Weird";
       }
           else{
               if(n>2 && n<=5){
                   ans = "Not Weird";
               }
               if(n>5 && n<=20){
                   ans = "Weird";
               }
               else{
                   ans = "Not Weird";
               }
            }
        System.out.println(ans);
    }
}

Problem solution in c++ programming.

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;


int main(){
    int N;
    cin >> N;
    if(N%2==0){
        if(N>20){
            cout<<"Not Weird";
        }
        if(N>=2 && N<=5){
            cout<<"Not Weird";
        }
        if(N>=6 && N<=20){
            cout<<"Weird";
        }
    }else{
        cout<<"Weird";
    }
    return 0;
}

Problem solution in c programming.

#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

int main(){
    int N; 
    scanf("%d",&N);
    if ((N % 2) != 0) {
        printf("Weirdn");
    } else if (N >= 2 && N <= 5) {
        printf("Not Weirdn");
    } else if (N >= 6 && N <= 20) {
        printf("Weirdn");
    } else {
        printf("Not Weirdn");
    }
    return 0;
}

Problem solution in Javascript programming.

process.stdin.resume();
process.stdin.setEncoding('ascii');

var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;

process.stdin.on('data', function (data) {
    input_stdin += data;
});

process.stdin.on('end', function () {
    input_stdin_array = input_stdin.split("n");
    main();    
});

function readLine() {
    return input_stdin_array[input_currentline++];
}

/////////////// ignore above this line ////////////////////

function main() {
    var N = parseInt(readLine());
    if (N % 2 === 0) {
        if (N >= 2 && N <= 5) {
            console.log("Not Weird");
        } else if (N >= 6 && N <= 20) {
            console.log("Weird");
        } else if (N > 20) {
            console.log("Not Weird");
        }
    } else if (N % 2 === 1) {
        console.log("Weird");
    }
}

30 days of code coding problems

Post navigation

Previous post
Next post
  • HackerRank Separate the Numbers solution
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
  • Hackerrank Day 6 Lets Review 30 days of code solution
©2025 Programming101 | WordPress Theme by SuperbThemes