Some error occured while loading page for you. Please try again.
Sort 70 Discussions, By:
Please Login in order to post a comment
Why does the Problem page suggest you to "P.S. Do try Solve Me First and Solve Me Second in Python before moving ahead."? We just learned how to use the print() function, how is anyone who's learning this going to understand how to define a function, assign values to variables, perform arithmetic, etc?
That's a good question.
twinkle twinkle little star
how i wonder what you are
up above the world sooo sky like the diamond in the sky
print "hello world!"
i am printing hello world like this but the output is not coming
it should be "Hello, World" u have missed some caps then ',' and an exclamation marks.
Here is Python solution from my HackerrankPractice repository:
Feel free to ask if you have any questions :)
What is up with the
if --name-- == 'main' ??
i havent good programing knowlage.
i havent any logic but i want to master in python can you help me
please give suggetion
This doesn't make any sense.
What is the biggest and most complicated code that has the output of "Hello, World!"?
It could be arbitrarily long just by adding more and more layers of complexity.
But here's my submission that I just did for a bit of fun:
from collections import namedtuple
LineLocation = namedtuple('LineLocation', ['line', 'position'])
if __name__ == '__main__':
rant = """Hacker Rank, What was it about your profile of
me that gave you the
Illusion that I would find this
challenge an interesting,
fun or useful programming task to complete? I
agree, when learning a new language it can
inform a new developer of the use of some features of its
code. Whereas, even the dumbest analysis of my
submissions should have shown you that time was long past in
Python for me.
I won't hold it against you however, for you have
a truly handy website with lots of other challenging and fun
lines = [line.strip() for line in rant.split('\n')]
locations = [LineLocation(z, z) for z in zip(lines, range(len(lines)))]
chars = [loc.line[loc.position:loc.position+1] for loc in locations]
message = ''.join(chars)
Care to explain how those last few lines work? I'm a noob.
lines is a list of strings from the input text, one for each line.
zip is used to get esch line along with an incrementing integer, which are put into a LineLocation object.
The square brackets are a "list comprehension", which means that any code inside the brackets operates on the provided list (the result of zip() here) and is then put into another list. here the outpu list is locations, which is a list of LineLocation objects.
Next I use another list conprehension to convert the list of locations into a list of strings called chars, each string is one character long and comes from taking the nth character of the line.
finally, join() is used in the chars list to convert it into a string.
I hope that clarifies things, ask again if not!
what is the longest code that still answers the question?
Can someone help with this practice exercise?
Write Python codes to develop a product recording system. It should allow the user to type product names one by one until he/she enters an empty product name. Display the entered product names and quantities so that each line is formatted as “-‐-‐-‐[product name]: [quantity].” For example, a user types ‘beef’, ‘beef’, ‘milk’, ‘steak’, ‘tomato’, ‘potato’, ‘milk’, tomato’, ‘potato’, ‘beef’. Your program should display at the end:
The products you entered and quantities are:
-‐-‐-‐ beef: 3
-‐-‐-‐ milk: 2
-‐-‐-‐ steak: 1
-‐-‐-‐ tomato: 2
-‐-‐-‐ potato: 2
Note: the order of the product names does not matter.
product = 
quantity1 = 
products = input("Enter the product name: ")
if products == 'exit':
quantity = input("Enter the quantity of products: ")
for x in range(0,len(product)):
print("you have %s number of %s"%(quantity1[x],product[x]))