Activity/Coding Test

[HackerRank][Python] Intro to Conditional Statements

Basha 2023. 4. 11. 11:59
728x90

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 n is 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.

#!/bin/python3

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 in range(2,6):
        print("Not Weird")
    elif N in range(6,21):
        print("Weird")
    else:
        print("Not Weird")

This code will first read an integer input from the user using the 'input()' function and conver it to integer using the 'int()' function,

728x90
반응형