February 21st, 2013, 11:22 AM
Printing Triangular Numbers
Hi, i have a wrote a program with the code:
To print triangular numbers such as 1,3,6,10..etc.
But im not too sure how im meant to print the actual numbers? Could anybody give me a hand? Thank you
February 21st, 2013, 12:22 PM
for n in range(10):
[/code] are essential for python code and Makefiles!
February 21st, 2013, 12:40 PM
You could do it this way ...
if n <= 0:
return n + triangle(n-1)
for n in range(1, 16):
print("%2d --> %d" % (n, triangle(n)))
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25
February 22nd, 2013, 12:03 AM
IMHO a for() loop is easier.
for x in range(1, 5):
num += x
February 22nd, 2013, 12:34 PM
from itertools import accumulate
print(*accumulate(range(1, 10)), sep=", ")
Last edited by Nyktos; February 22nd, 2013 at 12:47 PM.