Day 3: Intro to Conditional Statements

Sort by

recency

|

1786 Discussions

|

  • + 0 comments

    Use an uppercase N

  • + 0 comments

    n=int(input("enter the no.")) if((2<=n<=5)%2==0): print(n) else: print("wrong no")

    HI, friends, I got an error on this code that I want the values from 2 to 5 but I found that this statement always gave a true and display the output any friend can explain why this is happening

  • + 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);
    

    }