I just wanted to start posting entries on Python. Decided to start with the Introduction section found at HackerRank using the following URL: https://www.hackerrank.com/domains/python/py-introduction
Following is a list of challenges in the Intro section:
Say “Hello, World! With Python:
Not much to say. Following is my solution in Python using Visual Studio Professional 2013 IDE:
print(“Hello, World!”)
The output from a console follows:
Hello, World!
Press any key to continue . . .
Reading Raw Input:
As usual, I tried something before looking at the format required by the challenge. My code follows:
s = input()
print(s)
The output follows:
How many chickens does it take to cross the road?
How many chickens does it take to cross the road?
Press any key to continue . . .
The output matches, but the Current Buffer window contained the following code:
def read():
s =
return s
The solution requires a function. I updated the code. Following is a screen capture of the console:
How many chickens does it take to cross the road?
How many chickens does it take to cross the road?
Press any key to continue . . .
The sample output matches.
Following is the code for my solution:
# **** function definition ****
def read():
s = input()
return s
# **** my test ****
print(read())
The main for the challenge follows:
if __name__ == ‘__main__’:
my_str = read()
print my_str
By the way, my code failed. I had to set the language in the drop down menu to Python 3. After that the 3 test cases passed.
I ran out of time for the day but will continue early tomorrow morning.
If you have comments or questions regarding this of any other post in this blog, please feel free to send me a message via email. I will not mention your name unless you explicitly tell me to do so.
John
john.canessa@gmail.com
Follow me on Twitter: @john_canessa