Day 3: Intro to Conditional Statements

Sort by

recency

|

1789 Discussions

|

  • + 0 comments
    if N % 2 != 0:
        print('Weird')
    elif N % 2 == 0 and 2 <= N <= 5:
        print('Not Weird')
    elif N % 2 == 0 and 6 <= N <= 20:
        print('Weird')
    else:
        print('Not Weird')
    
  • + 1 comment
            if(N%2==0){
                if(N<=5 || N>20){
                    System.out.println("Not Weird");
                }
                else if(N>=6 && N<=20){
                    System.out.println("Weird");
                }
            }
            else{
                System.out.println("Weird");
            }
    
    • + 0 comments

      This logic works I tried it.

  • + 0 comments

    import java.io.*;

    public class Solution { public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));

        int N = Integer.parseInt(bufferedReader.readLine().trim());
    
    
        String weird=(N%2!=0)?"Weird":N>=6&&N<=20?"Weird":"Not Weird";
        System.out.println(weird);
        bufferedReader.close();
    }
    

    }

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