Day 3: Intro to Conditional Statements

Sort by

recency

|

1768 Discussions

|

  • + 0 comments
    if __name__ == '__main__':
        N = int(input().strip())
        if N % 2 != 0 or 6 <= N <= 20:
            print('Weird')
        else:
            print('Not Weird')
    
  • + 0 comments

    please vote me up: (JAVASCRIPT)

    function main() {
      const N = parseInt(readLine().trim(), 10);
      if (N % 2 !== 0) {
        console.log("Weird");
      } else if (N >= 2 && N <= 5) {
        console.log("Not Weird");
      } else if (N >= 6 && N <= 20) {
        console.log("Weird");
      } else {
        console.log("Not Weird");
      }
    }
    
  • + 0 comments
    if N % 2 != 0:
        print('Weird')
    elif 6 <= N <= 20:
        print('Weird')
    else:
        print('Not Weird')
    

    There's no need to bother with the 'Not Weird' conditionals because else will catch everything that is not 'Weird'.

  • + 0 comments
    #include <bits/stdc++.h>
    
    using namespace std;
    
    
    int main()
    {
       int n;
       cin>>n;
    
    
    if(n%2 == 0){
    if( (n%2 == 0) && n>=2 && n<=5)
    cout<<"Not Weird";
    
    if( (n%2 == 0) && n>=6 && n<=20 )
    cout<<"Weird";
    
    if(n>20)
    cout<<"Not Weird";
    }
    else 
    {
        cout<<"Weird";
    }
    
        return 0;
    }
    
    string ltrim(const string &str) {
        string s(str);
    
        s.erase(
            s.begin(),
            find_if(s.begin(), s.end(), not1(ptr_fun<int, int>(isspace)))
        );
    
        return s;
    }
    
    string rtrim(const string &str) {
        string s(str);
    
        s.erase(
            find_if(s.rbegin(), s.rend(), not1(ptr_fun<int, int>(isspace))).base(),
            s.end()
        );
    
        return s;
    }
    
  • + 0 comments

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