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 , define a function Get_Stations(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.
Example-1
Example-2
Example-3
Input:
12
4
Â
Output:
126
Input:
16
5
Â
Output:
792
Input:
2
4
Â
Output:
No Station
import math
def sol_int(N, S):
n = N - S + 1
sol = math.factorial(n)/(math.factorial(S) * math.factorial(n-S))
return sol
sol_int(16, 5)
792.0
Comments
Leave a comment