Conditional Statements
Conditional statements are condition that allow to execute a block of code if certain conditions are meet. IF/Elif/Else are one type of conditional statement.
In this problem we will print Weird/Not Weird
based on number provided by the user.
Task
Given an integer, , perform the following conditional actions:
If is odd, print Weird
If is even and in the inclusive range of 2 to 5, print Not Weird
If is even and in the inclusive range of 6 to 20, print Weird
If is even and greater than 20, print Not Weird
Conditional Statement Solution Hackerrank Solution In Python
if __name__ == "__main__":
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")
Conditional Statement Solution Hackerrank Solution In JavaScript(Js)
function main() {
const N = parseInt(readLine(), 10);
if (N % 2 != 0) {
console.log('Weird')
} else if (N > 20) {
console.log('Not Weird')
} else if (N >= 6) {
console.log('Weird')
} else if (N >= 2) {
console.log('Not Weird')
}
}
Check out 30 Days of Code| CodePerfectplus for All solutions from this series.
Top comments (0)