Talk:Pascal's triangle: Difference between revisions

m (fix another typo)
Line 14:
I think that maybe all example output should follow the task description format of an isosceles triangle. --[[User:Paddy3118|Paddy3118]] 08:59, 27 December 2009 (UTC)
:That's not always easy to do. I think the important part of the task is the generation of each row. We don't need to complicate it with output formatting that isn't important to the theory involved. --[[User:Mwn3d|Mwn3d]] 18:37, 27 December 2009 (UTC)
 
::Need it or not, the Python~2 code as available strays from theory by virtue of the return statement and status as a function rather than a complete program. I submit that completeness and conformity trumps raw theory in the case of code examples and would serve a broader public with formatting applied. I further submit the following additions as alternative and addition to present code under the potential heading of "Traditionally Formatted, Python~3":
::<lang python>def pascal(n):
# Prints out n rows of Pascal's triangle, traditionally formatted.
# Good for 1 <= n <= 20 rows.
row = [1]
k = [0]
z = n-1
for x in range(max(n,0)):
tabs = ' '*z
for i in range(len(row)):
row[i] = str(format(row[i], '6d'))
print(tabs+''.join( str(row[i]) for i in range(len(row)) ), sep='')
for i in range(len(row)):
row[i] = int(row[i])
row=[l+r for l,r in zip(row+k,k+row)]
z -= 1</lang>Likely, there are more elegant ways. This is to my ability. --[[User:Jnever1|Jnever1]] 04:35, 14 March 2012 (UTC)
 
== J Explanation ==
Anonymous user