From 1ed3e32dcc0f7684b3c881f8c011ccbf25e6db92 Mon Sep 17 00:00:00 2001 From: Rohit Barua <83600150+Rohit-beep-droid@users.noreply.github.com> Date: Sun, 23 May 2021 18:15:03 -0400 Subject: [PATCH] Update 100+ Python challenging programming exercises.txt An easy hackerrank challenge from 30 days of Code, which requires are good understanding of if-elif-else statements in Python. --- ...thon challenging programming exercises.txt | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/100+ Python challenging programming exercises.txt b/100+ Python challenging programming exercises.txt index 97af5aaf..f13a99ff 100644 --- a/100+ Python challenging programming exercises.txt +++ b/100+ Python challenging programming exercises.txt @@ -2371,5 +2371,33 @@ solutions=solve(numheads,numlegs) print solutions #----------------------------------------# +Level: Easy +Question: +Given an integer input, n, perform the following conditional actions: + +1. If n is odd, print "Weird". +2. If n is even and in the inclusive range of 2 to 5, print "Not Weird". +3. If n is even and in the inclusive range of 6 to 20, print "Weird". +4. If n is even and greater than 20, print "Not Weird". + +(credit: HackerRank (30 days of Code)) +Hints: Use if-elif-else statements to split the problem into sections. + +Answer: + +import math +import os +import random +import re +import sys + +if __name__ == '__main__': + n = int(input().strip()) + if(n%2!=0 or (n%2==0 and (n>=6 and n<=20))): + print('Weird') + else: + if((n%2==0 and (n>=2 and n<=5) or (n%2==0 and n>20))): + print('Not Weird') +#----------------------------------------#