Do not have much time this morning so I just addressed the next challenge in the Python Introduction set at HackerRank named Python If-Else that you can find at: https://www.hackerrank.com/challenges/py-if-else
This challenge tests the ability to write a set of correct if-then-else set of statements (including nested conditions).
Following is the output from IDLE for the test cases:
================================ RESTART: C:/Temp/PythonIfElse.py ================================
3 <== sample input
Weird
>>>
================================ RESTART: C:/Temp/PythonIfElse.py ================================
24 <== sample input
Not Weird
>>>
I am running on my development machine:
C:\> python -V
Python 3.5.2
My solution follows:
if __name__ == ‘__main__’:
n = int(input())
if (n % 2 == 1):
# **** odd number ****
print(“Weird”)
else:
# **** even number ****
if (n >= 2) and (n <= 5):
print(“Not Weird”)
elif (n >= 6) and (n <= 20):
print(“Weird”)
else:
print(“Not Weird”)
If you have comments or questions regarding this post or any other entry in this blog please do not hesitate and send me a message via email. Will answer as soon as possible and will not use your name unless you explicitly tell me to do so.
John
john.canessa@gmail
Follow me on Twitter: @john_canessa