Created
March 16, 2010 20:45
-
-
Save Visgean/334478 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 -*- | |
# Pythagoras triangle in new version with yield! | |
def giveMeLines(numberOfLines): | |
line = [1] | |
for xexe in xrange(numberOfLines): | |
yield line | |
tempLine = [] # buffer for new elements | |
for index in range(len(line) + 1): | |
if index == 0 or index == len(line) : # beging of new line | |
element = 1 | |
else: | |
element = line[index-1] + line[index] | |
tempLine.append(element) | |
line = tempLine | |
numberOfLines = int(raw_input("How many lines do you want? ")) | |
for line in giveMeLines(numberOfLines): | |
print line |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment