There are N intermediate stations between two places A and B. Find the number of ways in which a train can be made to stop at S number of these intermediate stations so that no two stopping stations are consecutive. Write a python module Station.py for above and import the module in main program .In main program define a function Get-Station(N,S)
which takes value of N & S and return integer result as shown in example by calling the appropriate function implemented in Station.py module. Also handle the possible exceptions and display the exception message in form of string. Do not use input function provide input in fixed form.
For Example : 1) Input : N= 12 , S= 4
Output: 126
2) Input : N= 2 , S = 4
Output : 0
import math
def Get_Station(N, S):
n = N - S + 1
sol = math.factorial(n)/(math.factorial(S) * math.factorial(n-S))
return sol
Get_Station(16, 5)
792.0
Comments
Leave a comment