Jul-26-2018, 01:38 PM
What is Zen Python? Zen Python is:
Zen Python is not:
- One function.
- One parameter.
- Five lines (108 characters per line, 4 space indents).
- Cool and/or interesting.
Zen Python is not:
- Obfuscated.
- Using semi-colons.
- Counting the def statement.
- Criticism.
def sierpinski(n): pascal = [[1]] for level in range(2 ** n - 1): pascal.append([1] + [sum(pair) for pair in zip(pascal[-1], pascal[-1][1:])] + [1]) chars = [['A ' if number % 2 else ' ' for number in row] for row in pascal] [print(' ' * (2 ** n - row), ''.join(row_chars), sep = '') for row, row_chars in enumerate(chars)]
Output:>>> sierpinski(4)
A
A A
A A
A A A A
A A
A A A A
A A A A
A A A A A A A A
A A
A A A A
A A A A
A A A A A A A A
A A A A
A A A A A A A A
A A A A A A A A
A A A A A A A A A A A A A A A A
What's your Zen?
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures