
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Triangular Matchstick Number
In this article, we will learn about the solution to the problem statement given below.
Problem statement − We are given a number X which represents the floor of a matchstick pyramid, we need to display the total number of matchstick required to form a pyramid of matchsticks with x floors.
Now let’s observe the solution in the implementation below −
Example
#function def numberOfSticks(x): return (3 * x * (x + 1)) / 2 # main() n=21 a=numberOfSticks(n) print(int(a))
Output
693
All the variables are declared in the local scope and their references are seen in the figure above.
Conclusion
In this article, we have learned about how we can make a Python Program for Triangular Matchstick Number
Advertisements