Day 3: Intro to Conditional Statements

Sort by

recency

|

1775 Discussions

|

  • + 0 comments

    The code is failing the test for 24 but when I test it using custom output it's passing for the same number? COuld someone point out what am I doing wrong here? n = 0 if n % 2 != 0: print('Weird') elif n % 2 == 0 and n in range(2,5): print('Not Weird') elif n % 2 == 0 and n in range(6,20): print('Weird') elif n % 2 == 0 and n in range(21,100): print('Weird') else: print('Weird')

  • + 0 comments

    !/bin/python3

    import math import os import random import re import sys

    if name == 'main': n = int(input().strip()) if n % 2 != 0: print("Weird") elif n % 2 == 0 and n in range(2,5): print("Not Weird") elif n % 2 == 0 and n in range(6,21): print("Weird") if n % 2 == 0 and n >20: print("Not Weird")

  • + 0 comments
    #!/bin/python
    
    import math
    import os
    import random
    import re
    import sys
    
    
    
    if __name__ == '__main__':
        n = int(raw_input().strip())
        
        if(n%2!=0):
            print("Weird")
        elif((n%2==0)and(n>=2 and n<=5)):
            print("Not Weird")
        elif((n%2==0)and(n>=6 and n<=20)):
            print("Weird")
        elif((n%2==0)and(n>20)):
            print("Not Weird")
        else:
            print("Weird")
    
  • + 0 comments

    Python :

    N = int(input().strip())
    if (N % 2 != 0) or (N in range(6,21)):
        print("Weird")
    else:
        print("Not Weird")
    
  • + 0 comments

    C# Solution, a one-line lamba expression:

    Console.WriteLine(N % 2 == 0 && (N < 6 || N > 20) ? "Not Weird" : "Weird");