mercredi 7 octobre 2015

Generating Dynamic Square Pattern [Python Programming Language]

I've been tasked to create a simple application using python that will allows me to enter an integer which will then generate a series of pattern in an infinite loop.

Example #1: 3

Output:

xxx
x.x
xxx

...
.x.
...

...
...
...

...
.x.
...

xxx
x.x
xxx

(Cont.)

Example #2: 6

Output:

xxxxxx
x....x
x....x
x....x
x....x
xxxxxx

......
.xxxx.
.x..x.
.x..x.
.xxxx.
......

......
......
..xx..
..xx..
......
......

......
......
......
......
......
......

......
......
..xx..
..xx..
......
......

(Cont.)


Here are my codes so far.

import time
time.sleep(0.5)

size = int(input("input pattern size: "))

if(size < 3):
    while(size < 3):
        print("warning: pattern size should be at least 3!")
        size = int(input("input pattern size: "))

        if(size >= 3):
            #INSERT ELSE CODE HERE#
            break;

else:
    while(size >= 3):
        for n in range(size, 0, -1):
            #print(('x') * size)
            print('x' * n)
        print()

Thanks for all the help I can get, highly appreciated.

Aucun commentaire:

Enregistrer un commentaire