Python If-Else - Hackerrank solution

 

Python If-Else


Task


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 and greater than 20, print Not Weird


Solution:

import math
import os
import random
import re
import sys

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



Note:

This Code is Verified by all Test Cases.If any error occurs then Comment correct code Below in comment box.

Disclaimer:-

 The above hole problem statement is given by hackerrank.com, but the solution is generated by the CodexRitik . if any of the query regarding this post or website fill the following contact form Thank You. 


Python If-Else - Hackerrank solution Python If-Else - Hackerrank solution Reviewed by CodexRitik on March 15, 2020 Rating: 5

3 comments:

  1. The above hole problem statement is given by hackerrank.com, but the solution is generated by the CodexRitik . if any of the query regarding this post or website fill the following contact form Thank You.

    ReplyDelete

  2. import math
    import os
    import random
    import re
    import sys

    n = int(input("your required no:"))
    if n%2!=0:
    print("Weird")
    elif 2<=n<=5:
    print("Not Weird")
    elif 6<=n<=20:
    print("Weird")
    elif n>20:
    print("Not Weird")

    ReplyDelete
  3. we have to put any string inside input(),and it will be converted into int. the above mentioned program will help user to put input as required. otherwise it won't execute.

    ReplyDelete

Powered by Blogger.