This week is my first week in lycaeum , and it was my hard work week too.I start with basic commend in Unix,from "The UNIX Programming Environment",and its quite easy to understand from it.Along with Unix i starts to watching Emacs videos and also starts to do the exercises in "Learn python 3 The hard way ". Right now am going to explain an a problem in python done in last week.
The problem is to find biggest two element from a list.
Here i have a list n=[10,12,5,15,9,16]. i will set first two numbers to two variables x and y.
x=n and y=n
Then check biggest from these two by using if loop
here if x < y then value will interchange it .else it's value be same.once we have the biggest in x and second biggest in y we can start to compare with other each element in list by using for loop and with if-else loop.
def big(n): x=n y=n if (x<y): y=n x=n for i in range(2,len(n)): if (x<n[i]): y=x x=n[i] elif(y<n[i]): y=n[i] print (x,y)
here we starts with 2th index number in the list.First we check the x<n[i],once the x< third element,it will set the value in x to y and x is set to that element.if this condition is not true,it continues x as the biggest and it move to elif loop.Here it check second biggest element that is y with the n[i] and if this condition is true then it change y is to n[i].ie it become the second biggest element in the list.it will continues until it reach the last element in the list.Finally we get the two biggest element as x and y.(x =first biggest and y=second biggest) .
i think you all got it.....thank you....