Skip to content

Update 100+ Python challenging programming exercises.txt #150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions 100+ Python challenging programming exercises.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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')
#----------------------------------------#