Welcome to the Pascal's Triangle project for the ALX Interview Preparation. In this project, you will implement an algorithm in Python to generate Pascal's Triangle up to a given number of rows.
By completing this project, you will:
- 🔢 Understand Pascal's Triangle: Learn how to generate Pascal’s Triangle, a triangular array where each number is the sum of the two directly above it.
- 🗂️ Python Lists and List Comprehensions: Revise how to create, access, modify, and iterate over lists. Use list comprehensions for concise and readable code.
- 🧠 Functions and Recursion: Understand how to define and call functions, pass parameters, and return values. Optional: use recursion for generating rows of the triangle.
- 🔄 Loops and Conditional Statements: Implement logic using loops and conditionals to handle edge cases, such as the first and last elements in each row.
- ➕ Arithmetic Operations: Perform addition, the essential operation for generating the elements of Pascal's Triangle.
- 🔢 Indexing and Slicing: Master accessing list elements and slices, crucial for summing up values to generate new rows.
This project includes the following:
-
🛠️ Pascal's Triangle Function
- File: 0-pascal_triangle.py
- Description: Implements the
pascal_triangle(n)function that returns a list of lists of integers representing Pascal's Triangle of sizen. It returns an empty list ifn <= 0.
-
🧪 Main File for Testing
- File: 0-main.py
- Description: Contains a test case that calls the
pascal_triangle()function withn = 5and prints the triangle.
This project is licensed under the terms of the MIT License.
© 2024 ALX. All rights reserved.