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 RollNo_W12B_3.py. In RollNo_W12B_3.py, 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:
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(12, 4)
126.0
Comments
Leave a comment