Hello coders, today we will be solving Python If-Else Hacker Rank solution.
Problem
Given an integer, n, perform the following conditional actions:
- If n is odd, print Weird
- If n is even and in the inclusive range of 2 to 5, print Not Weird
- If n is even and in the inclusive range of 6 to 20, print Weird
- If n is even greater than 20, print Not Weird
Input Format
A single line containing a positive integer, n.
Constraints
1 ≤ n ≤ 100
Output Format
Print Weird if the number is weird. Otherwise, print Not Weird.
Sample Input
3
Sample Output
Weird
Explanation 0
n = 3
n is odd and odd numbers are weird, so print Weird.
Sample Input 1
24
Sample Output 1
Not Weird
Explanation 1
n = 24
n > 20 and n is even, so it is not weird.
Solution – Python If-Else Hacker Rank Solution
n = int(input()) if n % 2 == 1: 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")
Disclaimer: The above Problem (Python If-Else) is generated by Hacker Rank but the Solution is provided by CodingBroz.
sir can i code like this….i’m a beginner incoding
n= int(input())
if n%2==1:
print(‘weird’)
elif n%2==0 and n>20:
print(‘not weird’)
elif n%2==0 and n==range(2,5):
print(‘not weird’)
elif n%2==0 and n==range(6,20):
print(‘not weird’)
hey even I tried like this but getting an error when I use a range
Because range function consider upto n-1 for number only
n= int(input())
if n%2==1:
print(‘weird’)
elif n%2==0 and n>20:
print(‘not 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(‘not weird’)
can anybody tell me what is wrong with my code
N = int(input().strip())
if N%2==0:
if N>20:
print(“not weird”)
elif N=6:
print(“weird”)
elif N>=2 and N<=5:
print("not weird")
else:
print("weird")
Given an integer, n, perform the following conditional actions:
If n is odd, print Weird
If n is even and in the inclusive range of 2 to 5, print Not Weird
If n is even and in the inclusive range of 6 to 20, print Weird
If n is even greater than 20, print Not Weird
Bro its nothing:
If n is even and in the inclusive range of 6 to 20, print Weird here I think you made a mistake it says that the range between(6 and 20)
Then here (elif N>=2 and N<=5:)
print("weird") you forgot to mention (odd or even)
def weird(n):
if n%2!=0:
print(“Weird”)
elif n%2==0 and n>20:
print(“Not Weird”)
elif n%2==0 and n in range(2,5):
print(“Not Weird”)
elif n==20:
print(“Weird”)
elif n%2==0 and n in range(6,20):
print(“Weird”)
if __name__ == ‘__main__’:
n = int(input().strip())
weird(n)
Today i strat my journey with this code. i am a beginner in coding.. pls help me to learn
n=int(input())
if n%2!=0:
print(“weird”)
elif n%2==0 :
if n>20 :
print(“not weird”)
elif 2<n and n<5 :
print("not weird")
elif 620:
print(“weird”)
please rectify error: code is working but, automatically it takes 3 input.
if __name__ == ‘__main__’:
n = int(input().strip())
if n % 2 != 0:
print(‘wired’)
elif n % 2 == 0 and n==range(2,5):
print(‘not wired’)
elif n % 2 == 0 and n==range(6,20):
print(‘wired’)
else:
print(‘not wired’)
sir can i code like this….i’m a beginner incoding
n= int(input())
if n%2==1:
print(‘weird’)
elif n%2==0 and n>20:
print(‘not weird’)
elif n%2==0 and n==range(2,5):
print(‘not weird’)
elif n%2==0 and n==range(6,20):
print(‘not weird’)
import math
import os
import random
import re
import sys
if __name__==’__main__’:
n=int(input().strip())
if (n%2==1):
print(“Weird”)
elif ((n%2==0),n in range(2,6)):
print(“Not Weird”)
elif ((n%2==0),n in range (6,21)):
print(“Weird”)
else:
print(“Not Weird”)
public static void main(String[] args) {
int N = scanner.nextInt();
scanner.skip(“(rn|[nru2028u2029u0085])?”);
scanner.close();
if((N%2!=0)||((N%2==0)&&(N<=6 &&N=20)||((N>=2)&&(N<=5)))
{
System.out.print("Not Weird");
}
}
}
n = int(input())
if n % 2 != 0:
print(“Weird”)
if n % 2 == 0 :
if n = 2:
print(“Not Weird”)
if n % 2 == 0 :
if n = 6:
print(“Weird”)
if n % 2 ==0 and n > 20:
print(“Not Wierd”)
i am gettting error why plz explain 24 , 100 is getting failed but its working in vs code plz help
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 and n=6 and n<=20:
print("Weird")
else:
print("Not weird")
why am i getting error in this code for some specific numbers??