Skip to content

Instantly share code, notes, and snippets.

@Visgean
Created February 22, 2010 00:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Visgean/310663 to your computer and use it in GitHub Desktop.
Save Visgean/310663 to your computer and use it in GitHub Desktop.
#! /usr/bin/python
# -*- coding: UTF-8 -*-
# Pascal´s Rectangle
start = int(raw_input("Starting number: "))
pascal = [[start]] # at least one item is necessary to be here
for cycle in range(int(raw_input("Number of lines: "))-1):
line = []
previous = pascal[-1]
lenghtOfNew = len(previous) + 1
for index in range(lenghtOfNew):
if index == 0: # beging of new line
element = pascal[-1][0]
elif index == len(pascal[-1]): # end of line
element = pascal[-1][index-1]
else:
element = pascal[-1][index-1] + pascal[-1][index]
line.append(element)
pascal.append(line)
for line in pascal:
print line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment