Python Forum
printing patterns and stars?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
printing patterns and stars?
#6
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)
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
printing patterns and stars? - by msa969 - Feb-21-2017, 08:04 AM
RE: printing patterns and stars? - by j.crater - Feb-21-2017, 08:08 AM
RE: printing patterns and stars? - by wavic - Feb-21-2017, 08:39 AM
RE: printing patterns and stars? - by ichabod801 - Feb-22-2017, 02:03 AM
RE: printing patterns and stars? - by wavic - Feb-22-2017, 02:13 AM
RE: printing patterns and stars? - by ichabod801 - Feb-22-2017, 02:25 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  help me to find turtle codes for those patterns hammza 0 1,482 May-12-2020, 12:14 PM
Last Post: hammza

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020