Day 3: Intro to Conditional Statements
Day 3: Intro to Conditional Statements
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
Complete the stub code provided in your editor to print whether or not is weird.
Input Format
A single line containing a positive integer, n.
Output Format
Print Weird if the number is weird; otherwise, print Not Weird.
Sample Input 0
3
Sample Output 0
Weird
Sample Input 1
24
Sample Output 1
Not Weird
In CPP Solution:
#include <iostream>
using namespace std;
int main() {
int N;
cin >> N;
if (N % 2 != 0)
cout << "Weird";
else {
if (N <= 5)
cout << "Not Weird";
else if (N <= 20)
cout << "Weird";
else
cout << "Not Weird";
}
}
In Python Solution:
import math
import os
import random
import re
import sys
n=int(input())
if n%2!=0:
print("Weird")
elif (n in range(2,6)):
print("Not Weird")
elif (n in range(6,21)):
print("Weird")
elif (n>20):
print("Not Weird")