Find sum of series 1+2+8+26+80+…….+n

we can not define 1+2+8+26+80+.......... series in a simple manner to write  program. But..... 2,8,26,80,242.................can be define as below The way to discover the next term is multiply the next number by 2 and then add it on. i.e. the next number of 2 is 3 so, 3*2=6+2=8 9*2=18+8=26 27*2=54+26=80........ and so on             OR … Continue reading Find sum of series 1+2+8+26+80+…….+n

Advertisements

Polar Coordinates

Task You are given a complex z. Your task is to convert it to polar coordinates. Input Format A single line containing the complex number z. Output Format Output two lines: The first line should contain the value of r. The second line should contain the value of Φ. Sample Input 1+2j Sample Output 2.23606797749979 … Continue reading Polar Coordinates

Set .add()

Task Apply your knowledge of the .add() operation to help your friend Rupal. Rupal has a huge collection of country stamps. She decided to count the total number of distinct country stamps in her collection. She asked for your help. You pick the stamps one by one from a stack of N country stamps. Find … Continue reading Set .add()

Find the Second Largest Number

You are given N numbers. Store them in a list and find the second largest number. Input Format The first line contains N. The second line contains an array A[] of N integers each separated by a space.     if __name__ == '__main__': n = int(input()) arr = map(int, input().split()) print(sorted(list(set(arr)))[-2])

List Comprehensions

Let's learn about list comprehensions! You are given three integers X,Y and Z representing the dimensions of a cuboid along with an integer N. You have to print a list of all possible coordinates given by  (i,j,k) on a 3D grid where the sum of  i+j+k  is not equal to N . Here, 0<=i<=X;0<=j<=Y;0<=k<=Z Input … Continue reading List Comprehensions