Skip to content

Latest commit

 

History

History
72 lines (57 loc) · 1.83 KB

README.md

File metadata and controls

72 lines (57 loc) · 1.83 KB

📖 0x00. Pascal's Triangle

Topics Covered

  1. Python.
  2. Pascal's Triangle.

💻 Tasks.

Task requirements.

Create a function def pascal_triangle(n): that returns a list of lists of integers representing the Pascal’s triangle of n:

  • Returns an empty list if n <= 0
  • You can assume n will be always an integer
guillaume@ubuntu:~/0x00$ cat 0-main.py
#!/usr/bin/python3
"""
0-main
"""
pascal_triangle = __import__('0-pascal_triangle').pascal_triangle

def print_triangle(triangle):
    """
    Print the triangle
    """
    for row in triangle:
        print("[{}]".format(",".join([str(x) for x in row])))


if __name__ == "__main__":
    print_triangle(pascal_triangle(5))

guillaume@ubuntu:~/0x00$ 
guillaume@ubuntu:~/0x00$ ./0-main.py
[1]
[1,1]
[1,2,1]
[1,3,3,1]
[1,4,6,4,1]
guillaume@ubuntu:~/0x00$ 

🔧 Task setup.

# Create task file and set write permission.
touch ./0-pascal_triangle.py
chmod +x ./0-pascal_triangle.py
./0-pascal_triangle.py

pycodestyle ./0-pascal_triangle.py
pep8 ./0-pascal_triangle.py

# Create test file
touch ./0-main.py
chmod +x ./0-main.py
./0-main.py

✔️ Solution.

👉 Go to 1-promise.js

📚 References

  1. Pascal's Triangle
  2. Python Lists

👨 Author and Credits.

This project was done by SE. Moses Mwangi. Feel free to get intouch with me;

📱 WhatsApp +254115227963

📧 Email [email protected]

👍 A lot of thanks to ALX-Africa Software Engineering program for the project requirements.