Skip to main content

Posts

Showing posts from February, 2018

Understand the generators and yield keyword in python, on Python Hunter

Generators look like a function but there is huge difference b/w generators and function. Instead of return statements you will find only yield statements are used inside of the body of a generator , i.e. one or more yield statements.  In short the main feature of generator is that the last execution statement is kept remembered by python interpreter and the next time when the same generator is called the it execute from the last yield location instead of starting the location from TOP. And the state of all local variable(s) are kept safe, that means the local variable(s) will not change their value(s) at next call.      Follow the example to understand the concept. def gen():     yield 1     yield 2     yield 3     yield 4 f=gen() print(next(f)) # will print 1 print(next(f)) # will print 2 print(next(f)) # will print 3 Let's take a real example........... --------------------------------------------------CODE STARTS------------------------------

Whats App Tricks.

      Top 42 Secret whatsapp tricks you never knew  Whatsapp is the most famous mobile messaging platform till date. But do you know some of the secrets tricks of whatsapp which can take you to the next level. Here in this article, i am highlighting most famous whatsapp tricks So far. - ------------------------------------------------------------------------------------------ Click here to learn more. -----------------------------------------------

This post to make you familiar with some basic whatsapp tricks.

15 Whats App tricks that will just blow your mind and help you be safe. WhatsApp. Wonderful, wonderful, WhatsApp. The messaging service that made BBM look boring and text messages redundant. Of course there are now heaps of messaging services around, but WhatsApp has had a massive head start on almost all of them, meaning it has tonnes of features. WhatsApp on Amazon US - Amazon UK You can read all about what it is and how it works in our WhatsApp feature, but for those who already know the beauty of the service, here are some secret tips you might not know about. - ----------------------------------------------------------------------------------------------------- Click here to learn tricks.... ----------------------------------------------------------------------------------------------------

Hackthon Challenge.....

Roy wants to change his profile picture on Facebook. Now Facebook has some restriction over the dimension of picture that we can upload. Minimum dimension of the picture can be  L x L , where  L  is the length of the side of square. Now Roy has  N  photos of various dimensions. Dimension of a photo is denoted as  W x H where  W  - width of the photo and  H  - Height of the photo When any photo is uploaded following events may occur: [1] If any of the width or height is less than L, user is prompted to upload another one. Print " UPLOAD ANOTHER " in this case. [2] If width and height, both are large enough and (a) if the photo is already square then it is accepted. Print " ACCEPTED " in this case. (b) else user is prompted to crop it. Print " CROP IT " in this case. ------------------------------------------------------------------- # Write your code here l_=int(input()) case_=int(input()) while(case_!=0):     dimes_=input()  

User Defined Exception in python. On Python Hunter

Exceptions in any programming language are the unexpected output of a script. Traditional example is dividing a number with zero (1/0). These exceptions will obviously halt our code. But if we use the try catch block then we can justify our code to keep executing. Sometimes we need to raise some exceptions to guide the user or program to go in specific direction. For Instance, the average salary of accounts department should not be greater than 40000 , now integer value 40001 is normal and there is nothing wrong with it, even the compiler or interpreter will not find any issue regarding that. But, we programmers know that 40001 will be wrong input value for average salary of accounts department, we need to inform the user that 40001 is wrong value as it cannot be greater than 40000 . Here the User Defined Exceptions topic comes in light. Follow the code to understand the concept.      1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26