printing patterns and stars? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: General (https://python-forum.io/forum-1.html) +--- Forum: News and Discussions (https://python-forum.io/forum-31.html) +--- Thread: printing patterns and stars? (/thread-2130.html) |
printing patterns and stars? - msa969 - Feb-21-2017 I am a newbie to python and using python 3. I wish to learn patterns and printing e.g stars etc. I want to start basic patterns first eg. * ** *** **** Is there a website or document like pdf that will teach me this and perhaps answers to check against when i go wrong? RE: printing patterns and stars? - j.crater - Feb-21-2017 Hello, I am not familiar with any document (nor did I search, really..). But if you look into "ASCII art" you might find a lot of resources for what you are after. As far as Python goes, "print" statement will be your best friend in drawing patterns. RE: printing patterns and stars? - wavic - Feb-21-2017 Simple example: In [14]: for i in range(1, 30, 2): ...: print('*' * i) ...: * *** ***** ******* ********* *********** ************* *************** ***************** ******************* ********************* *********************** ************************* *************************** In [15]: print('oh, yes! ' * 10) oh, yes! oh, yes! oh, yes! oh, yes! oh, yes! oh, yes! oh, yes! oh, yes! oh, yes! oh, yes! RE: printing patterns and stars? - ichabod801 - Feb-22-2017 numbers = {'***': 128, '** ': 64, '* *': 32, '* ': 16, ' **': 8, ' * ': 4, ' *': 2, ' ': 1} def eca(rule, n = 18, start = '*'): rule_bin = reversed(bin(rule)[2:]) last = start for generation in range(n): print(last) last = ' {} '.format(last) next = '' for index in range(len(last) - 2): if rule & numbers[last[index:index + 3]]: next += '*' else: next += ' ' last = next eca(18) RE: printing patterns and stars? - wavic - Feb-22-2017 RE: printing patterns and stars? - ichabod801 - Feb-22-2017 import random numbers = {'***': 128, '** ': 64, '* *': 32, '* ': 16, ' **': 8, ' * ': 4, ' *': 2, ' ': 1} def box(rule, n = 23, width = 79): last = '' for cell in range(width): if random.random() < 0.5: last += '*' else: last += ' ' for generation in range(n): print(last) last = ' {} '.format(last) next = '' for index in range(len(last) - 2): if rule & numbers[last[index:index + 3]]: next += '*' else: next += ' ' last = next box(30) |