Given N and Standard Deviation , find N elements | Python program to find n elements ; function to print series of n elements ; if S . D . is 0 then print all elements as 0. ; print n 0 's ; if S . D . is even ; print - SD , + SD , - SD , + SD ; if odd ; if odd convert n to a float integer ; print one element to be 0 ; print ( n - 1 ) elements as xi derived from the formula ; driver code to test the above function
import math NEW_LINE def series ( n , d ) : NEW_LINE INDENT if d == 0 : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT print ( "0" , end = ' ▁ ' ) NEW_LINE DEDENT return 1 NEW_LINE DEDENT if n % 2 == 0 : NEW_LINE INDENT i = 1 NEW_LINE while i <= n : NEW_LINE INDENT print ( " % .5f " % ( ( math . pow ( - 1 , i ) * d ) ) , end = ' ▁ ' ) NEW_LINE i += 1 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT m = n NEW_LINE r = ( m / ( m - 1 ) ) NEW_LINE g = ( float ) ( d * float ( math . sqrt ( r ) ) ) NEW_LINE print ( "0 ▁ " , end = ' ▁ ' ) NEW_LINE i = 1 NEW_LINE while i < n : NEW_LINE INDENT print ( " % .5f " % ( math . pow ( - 1 , i ) * g ) , end = ' ▁ ' ) NEW_LINE i = i + 1 NEW_LINE DEDENT DEDENT print ( " " ) NEW_LINE DEDENT n = 3 NEW_LINE d = 3 NEW_LINE series ( n , d ) NEW_LINE