
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python Program to Print the Pascal's triangle for n number of rows given by the user
When it is required to print the pascal’s triangle for a specific number of rows, where the number is entered by the user, a simple ‘for’ loop is used.
Below is the demonstration of the same −
Example
from math import factorial input = int(input("Enter the number of rows...")) for i in range(input): for j in range(input-i+1): print(end=" ") for j in range(i+1): print(factorial(i)//(factorial(j)*factorial(i-j)), end=" ") print()
Output
Enter the number of rows...6 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1
Explanation
The required packages are imported.
The number of rows is taken as input from the user.
The number is iterated over in the form of a nested loop.
The factorial method is used to print the pascal’s triangle on the console.
- Related Articles
- C++ Program to Print Number Entered by User
- Python program to print number triangle
- Python program to print all the numbers divisible by 3 and 5 for a given number
- Python program to print palindrome triangle with n lines
- Python Program for Efficient program to print all prime factors of a given number
- Python Program to print a specific number of rows with Maximum Sum
- Java program to print the reverse of the given number
- Java program to print the factorial of the given number
- C# program to print all the numbers divisible by 3 and 5 for a given number
- Python Program to Read a Number n And Print the Series "1+2+…..+n= "
- Program to print maximum number of characters by copy pasting in n steps in Python?
- Python Program to Print all Numbers in a Range Divisible by a Given Number
- Program to find last digit of the given sequence for given n in Python
- Golang Program to Print the Multiplication Table of a Given Number
- Python Program to Read a Number n and Print the Natural Numbers Summation Pattern

Advertisements