- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
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 to print palindrome triangle with n lines
Suppose we have a number n. We have to find a triangle with n rows and each row contains palindrome.
So, if the input is like n = 5, then the output will be
1 121 12321 1234321 123454321
To solve this, we will follow these steps −
- for i in range 1 to n, do
- display ((integer part of (10^i) - 1)/9)^2
- go to next line
Example
Let us see the following implementation to get better understanding −
def solve(n): for i in range(1,n+1): print((((10**i) - 1)//9)**2) n = 8 solve(n)
Input
8Output
1 121 12321 1234321 123454321 12345654321 1234567654321 123456787654321
Advertisements