Pascal Triangle Generator (Python 3.3) 05-14-2014, 03:41 PM
#1
On my way to improving my Python, I made this:
Pastebin link and Hastebin link for an easier way to read it.
Code:
import sys
import random
from math import factorial
f = factorial
def doTriangle(t):
for a in range(0, t + 1):
for b in range(0, a + 1):
x = f(a) / (f(b) * f(a - b))
print(int(x),end=" ")
print("")
print("Done!")
def main():
try:
if len(sys.argv) == 2:
doTriangle(int(sys.argv[1]))
else:
doTriangle(int(input("Compute up to: ")))
except ValueError:
x = int(random.randrange(2, 20))
print("Invalid input, randomly chose " + str(x) + ".")
doTriangle(x)
main()Pastebin link and Hastebin link for an easier way to read it.
![[Image: CDUAq9d.png]](http://i.imgur.com/CDUAq9d.png)





![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)