chevron_left chevron_right
Login Register invert_colors photo_library

Stay updated and chat with others! - Join the Discord!
Thread Rating:
  • 0 Vote(s) - 0 Average

Pascal Triangle Generator (Python 3.3) filter_list
Pascal Triangle Generator (Python 3.3) #1
On my way to improving my Python, I made this:

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=" ")

def main():
        if len(sys.argv) == 2:
            doTriangle(int(input("Compute up to: ")))
    except ValueError:
        x = int(random.randrange(2, 20))
        print("Invalid input, randomly chose " + str(x) + ".")


Pastebin link and Hastebin link for an easier way to read it.
[Image: CDUAq9d.png]


Users browsing this thread: 1 Guest(s)