30 Day code challenge- python

Day 3- 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
Sample input and output

Input Format

A single line containing a positive integer, n.

Output Format

Print Weird if the number is weird; otherwise, print Not Weird.

Solution

Explanation

Line 1: Gets input from the user
Line 2: Checks whether the n has remainder as 1, if yes, then the output is “Weird”
Line 3: Checks whether the number is even and in the range 2 to 5 and prints “Not Weird”
Line 4, 5: Checks for different conditions and print “Weird” or “Not Weird”

Bonus Tip: Instead of elif we can use else if. To reduce the line of code elif is used

See you on day 4

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store