Created
February 22, 2010 00:59
-
-
Save Visgean/310663 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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