- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Program for Number of stopping station problem
In this article, we will learn about the solution to the problem statement given below.
Problem statement − We are given that there are 13 intermediate stations between two places A and B. We need to find the number of ways in which a train can be stopped at 2 intermediate stations, such that there are no consecutive stations?
Now let’s observe the solution in the implementation below −
# stop station def stopping_station( p, n): num = 1 dem = 1 s = p # selecting specified position while p != 1: dem *= p p-=1 t = n - s + 1 while t != (n-2 * s + 1): num *= t t-=1 if (n - s + 1) >= s: return int(num/dem) else: # condition return -1 # main num = stopping_station(2, 13) if num != -1: print("No of stopping stations:",num) else: print("I'm Possible")
No of stopping stations: 66
All the variables are declared in the local scope and their references are seen in the figure above.
In this article, we have learned about how we can make a Python Program for the Number of stopping station problems.
- C Program for Number of stopping station problem
- Python Program for Activity Selection Problem
- Python Program for Subset Sum Problem
- Python Program for 0-1 Knapsack Problem
- Find the Number of Stopping Stations using C++
- Minimum Number of Platforms Required for a Railway Station using C++.
- C Program for Activity Selection Problem
- Python Program for factorial of a number
- Python Program for nth Catalan Number
- Python Program for Triangular Matchstick Number
- Minimum Number of Platforms Problem
- Minimum Number of Jumps Problem
- Python Program for Find minimum sum of factors of number
- Python Program for n-th Fibonacci number
- Python Program for Find largest prime factor of a number