We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Python
  3. Introduction
  4. Python If-Else
  5. Discussions

Python If-Else

Problem
Submissions
Leaderboard
Discussions
Editorial
Tutorial

Sort 3348 Discussions, By:

recency

Please Login in order to post a comment

  • notlasaikanna09
    12 hours ago+ 0 comments

    what is the error in my code

    if (n%2!=0): print("Weird") elif(n>=2 and n<=5): if(n%2==0): print("Not Weird") elif(n>=6 and n<=20): if(n%2==0): print("Weid") elif(n>20): if(n%2==0): print("Not Weird")

    -5|
    Permalink
  • soumyadharani30
    2 days ago+ 0 comments

    import math import os import random import re import sys

    if name == 'main': n = int(input().strip()) assert (n >= 0 and n <= 100) if(n%2!=0): print("Weird") elif(n%2==0)&((n>=2)and(n>=5)): print("Not Weird") elif(n%2==0)&((n>=6)and(n<=20)): print("Weird")
    elif(n%2==0)&(n>20): print("Not Weird")

    0|
    Permalink
  • ohksk567
    3 days ago+ 0 comments

    why not accepted

    n = int(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') else: print("Not Weird")

    0|
    Permalink
  • jclarkbell
    4 days ago+ 0 comments

    Dont forget the assert statement at the start!

    n = int(input().strip())
        assert (n >= 0 and n <= 100)
        if n % 2 != 0 or (n >= 6 and n <= 20 and n % 2 == 0):
            print("Weird")
        elif n % 2 == 0 and ((n >= 2 and n <= 5) or n > 20):
            print("Not Weird")
    
    0|
    Permalink
  • giancarloromeo
    5 days ago+ 0 comments
    if __name__ == '__main__':
        n = int(input().strip())
    
        print("Weird" if n % 2 != 0 or 6 <= n <= 20 else "Not Weird")
    
    0|
    Permalink
Load more conversations

Need Help?


View tutorial
View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy