Hello Buddies,
This blog is about python interview questions How to solve with step by step process i will explain. So please read it carefully try to understand coding logic. let's start.
Question : Write a code to sum of squares of n natural numbers?
Before dive in to the code explanation 1st look at what is natural number and what is sum of square n natural number. Natural number is positive integers they start from +1 to +infinity. and it denoted by N = {1,2,3,4,.........}. Sum of squares of n natural numbers are 1^2 +2^2+3^2.........
So we need to find sum of n natural number like ex : if we take 4 we need to do 1^2+2^2+3^2+4^2 = 30. So this is sum of squares of n natural numbers. Let's look at code part
Code :
First take n input and sm = 0 it store sum value. and for i in range we all know it checks
Values based on our input. first sm = 0, sm = 0+1(1*1), in sm 1 value store next time, sm = 1 +(2*2) , 5 in sm now store value 5. this process will continue until it reach it end value.
Question : Find largest element in list?
We have one list in that one we need to find largest element in given list.
Code :
The given data is not in ascending it is in descending order so first we need to arrange in correct order for that we use sort function. this sort elements in ascending order. then Data[-1] will print last element. why last element means after ascending order largest value come in last so this will print largest number in list. Thank You.


Comments
Post a Comment