Skip to content

Instantly share code, notes, and snippets.

@Visgean
Created March 16, 2010 20:45
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/334478 to your computer and use it in GitHub Desktop.
Save Visgean/334478 to your computer and use it in GitHub Desktop.
#! /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