Day 3: Intro to Conditional Statements

Sort by

recency

|

1784 Discussions

|

  • + 0 comments

    For Csharp:

    if (N % 2 != 0) // If N is odd

        {
    
            Console.WriteLine("Weird");
        }
    
        else // If N is even
    
        {
    
            if (N >= 2 && N <= 5)
            {
    
                Console.WriteLine("Not Weird");
            }
            else if (N >= 6 && N <= 20)
            {
    
                Console.WriteLine("Weird");
    
            }
    
            else // N > 20
            {
    
                Console.WriteLine("Not Weird");
            }
        }
    }
    

    } Console.WriteLine("Weird"); }}}

  • + 0 comments

    solved in java!

        if(N%2==0)
        {
            if  ((2<=N && N<=5)|| N>20)
        {
            System.out.println("Not Weird");
        }
        else if (6<=N && N<=20)
        {
            System.out.println("Weird");
        }
        }
        else
        {
            System.out.println("Weird");
        }
    
  • + 0 comments

    function main() { const N = parseInt(readLine().trim(), 10); let result = "Weird";

    if (N % 2 != 0) {
        result = "Weird";        
    }else if ( N >=2 && N <= 5) {
        result = "Not Weird"; 
    }else if (N >= 6 && N <= 20 ) {
        result = "Weird"; 
    }else {
        result = "Not Weird"; }
    
    console.log(result);
    

    }

  • + 0 comments
    def weird_test(n):
        if (n % 2 != 0) or(6 <= n <= 20):
            print("Weird")
        else:
            print("Not Weird")
    
  • + 0 comments

    My solution is as follows:

    if __name__ == '__main__':
        N = int(input().strip())
        if N%2==1:
            print("Weird")
        elif N%2==0 and 2<=N<=5:
            print("Not Weird")
        elif N%2==0 and 6<=N<=20:
            print("Weird")
        elif N%2==0 and N>20:
            print("Not Weird")
        else:
            print("you entered the number out of constraint (1=<N=>100")