Video courses for company/skill based Preparation
Purchase mock tests for company/skill building
Python Program for Staircase Problem
TCS CodeVita is a coding competition organized by TCS every year in search for some of the best coders all over the world. This year it is the ninth season of this competition known as TCS CodeVita 2020 season 9. Before the actual competition TCS CodeVita gives a set of sample question, Staircase Problem is one of the sample question of this year TCS CodeVita Season 9. Here we have solved this problem in Python.
There are n stairs, a person standing at the bottom wants to reach the top. The person can climb either 1 stair or 2 stairs at a time.
- Count the number of ways, the person can reach the top.
n = int(input("Enter number of Stairs:")) def calc(x): if x <= 1: return x return calc(x - 1) + calc(x - 2) def count(n): return calc(n + 1) print("Number of ways:", count(n))
Output 5 8