Python

Pascal Row Generator

Given a pascal row the program returns the next iteration

The program gets the user input in a parses it and passes it to a function that will return the next row.

The pascRowNext() function check to see if the passed value is indeed a valid pascal row, and then uses a comprehension to return the next row. Each pascal row can be generated by appending a 0 to the end of the current row, creating a temporary value that is the inverse on the current row. Then zipping the two rows and summing corresponding index's.

Example:

> python pascal.py

> Input a pascal triangle row(ex. 1,2,1) > 1,2,4,2,1

> next row is

> Traceback (most recent call last):

> File "pascal.py", line 41, in

> print " next row is", pascRowNext(pascalRow)

> File "pascal.py", line 18, in pascRowNext

> raise Exception('The input list is not part of the pascal sequence')

> Exception: The input list is not part of the pascal sequence

> python pascal.py

> Input a pascal triangle row(ex. 1,2,1) > 1,3,3,1

> next row is [1, 4, 6, 4, 1]