Probability of not getting two consecutive heads together in N tosses of coin | Python3 implementation to find the probability of not getting two consecutive heads together when N coins are tossed ; Function to compute the N - th Fibonacci number in the sequence where a = 2 and b = 3 ; The first two numbers in the sequence are initialized ; Base cases ; Loop to compute the fibonacci sequence based on the first two initialized numbers ; Function to find the probability of not getting two consecutive heads when N coins are tossed ; Computing the number of favourable cases ; Computing the number of all possible outcomes for N tosses ; Driver code
import math NEW_LINE def probability ( N ) : NEW_LINE INDENT a = 2 NEW_LINE b = 3 NEW_LINE if N == 1 : NEW_LINE INDENT return a NEW_LINE DEDENT elif N == 2 : NEW_LINE INDENT return b NEW_LINE DEDENT else : NEW_LINE INDENT for i in range ( 3 , N + 1 ) : NEW_LINE INDENT c = a + b NEW_LINE a = b NEW_LINE b = c NEW_LINE DEDENT return b NEW_LINE DEDENT DEDENT def operations ( N ) : NEW_LINE INDENT x = probability ( N ) NEW_LINE y = math . pow ( 2 , N ) NEW_LINE return round ( x / y , 2 ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 10 NEW_LINE print ( operations ( N ) ) NEW_LINE DEDENT