Skip to main content

Module for generating and printing Pascal's Triangle

Project description

pascal-triangle

image       GitHub       PyPI       PyPI - Python Version      

Module for generating and printing Pascal's Triangle

Requires Python 3.9 (type hints)

Explicit implementation of Pascal's Triangle algorithm. Each row can be generated separately from all others. This vastly speeds up time if all you need is row 100 for example. This module is intended to be useful for mathematics or anytime a row(s) of Pascal's triangle might be useful.

Installation

Pascal-triangle can be installed directly with pip to use as a library and shell command by running pip install pascal-tri

OR clone the repo and run python -m pascal

Includes methods for

  • generating a list of triangle rows
  • pretty printing a triangle with correct spacing and alignment

The pascal module defines the following methods, access with

from pascal import *
    # To generate a explicit row 'n' of Pascal's triangle:
        calculate_row(n: int) -> PascalRow

    # To generate a list of 'n' rows:
        pascal(n: int) -> PascalTriangle

    # Pretty print to stdout a triangle with 'n' rows or (optionally) a supplied triangle:
        print_pascal(n: int, triangle: PascalTriangle = None) -> None

Can be run as a script as well.

python -m pascal [-h] [-l LINES]
  If LINES not specified, runs in interactive loop

Learning objectives

This project exists as an exercise in learning these techonlogies/concepts

  • Python type hinting (VS code intellisense integration)
  • Making distributable Python packages (PyPi)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

pascal_tri-1.2.2-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file pascal_tri-1.2.2-py3-none-any.whl.

File metadata

  • Download URL: pascal_tri-1.2.2-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

File hashes

Hashes for pascal_tri-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 148a908484e5194084b7a3f4c9e9ba771168e18c7b67c4e2f08a69a3238db5ab
MD5 033aedb30f7992f7158515bd323f3774
BLAKE2b-256 5e7b03bc2d8644b3f46bbd63b554b528c6144106b2e57802ae2215d018860bcb

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page