Sinisterly
Bronze Python Challenge - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: Python (https://sinister.ly/Forum-Python)
+--- Thread: Bronze Python Challenge (/Thread-Bronze-Python-Challenge)

Pages: 1 2


Python Challenge - Nil - 10-18-2015

Write a program that will use nested loops to print the following pattern. You may use more than one set of nested loops if needed. You are allowed to use only print statements that print single asterisks.

The pattern:
[Image: 3ae6053bacbb3c183642d36e94a57abc.png]

Alternate link to image:
http://i1315.photobucket.com/albums/t595/Kanooey/Python_Challenge_AstPattern_zpsraluzuy2.png


RE: *Simple* Python Challenge - Eclipse - 10-18-2015

>simple
>couldn't solve it

pick one

OT: The image isn't loading for me.


RE: *Simple* Python Challenge - Nil - 10-18-2015

(10-18-2015, 08:12 PM)Eclipse Wrote: >simple
>couldn't solve it

pick one

OT: The image isn't loading for me.

I'll remove simple. The python knowledge needed and to be incorporated for the challenge is very little, yet it still causes confusion... Wasn't sure how to put it.

Not sure why it isn't loading. I can see it. I'll upload it real quick.


RE: Python Challenge - m0dem - 10-19-2015

Well, the world will be amazed, I just came up with a stunning solution.
Code:
import sys

def pad(n):
    sys.stdout.write(" " * n)

for a in range(0, 1):
    pad(3)
    for b in range(0, 1):
        sys.stdout.write("*")

    pad(3)
    print("")

    pad(2)
    for b in range(0, 3):
        sys.stdout.write("*")

    pad(2)
    print("")

    pad(1)
    for b in range(0, 5):
        sys.stdout.write("*")

    pad(1)
    print("")

    for b in range(0, 7):
        sys.stdout.write("*")

    print("")

    pad(1)
    for b in range(0, 5):
        sys.stdout.write("*")

    pad(1)
    print("")

    pad(2)
    for b in range(0, 3):
        sys.stdout.write("*")

    pad(2)
    print("")

    pad(3)
    for b in range(0, 1):
        sys.stdout.write("*")

    pad(3)
    print("")
Don't gag... I did. Tongue
No, jk... I will really try in a bit. xD

Hmm... actually I just came up with a compact solution. It follows all your rules, but I don't think it works the way you were intending. It's really funny how simple it is...
Code:
import sys

design = [
    "   *   ",
    "  ***  ",
    " ***** ",
    "*******",
    " ***** ",
    "  ***  ",
    "   *   "
]

for y in design:
    for x in y:
        sys.stdout.write(x)

    print("")



RE: Python Challenge - Eclipse - 10-19-2015

(10-19-2015, 04:45 AM)m0dem Wrote: Hmm... actually I just came up with a compact solution. It follows all your rules, but I don't think it works the way you were intending. It's really funny how simple it is...
Code:
import sys

design = [
    "   *   ",
    "  ***  ",
    " ***** ",
    "*******",
    " ***** ",
    "  ***  ",
    "   *   "
]

for y in design:
    for x in y:
        sys.stdout.write(x)

    print("")

Lmfao. 10/10 mate.


RE: Python Challenge - Nil - 10-19-2015

(10-19-2015, 04:45 AM)m0dem Wrote: Well, the world will be amazed, I just came up with a stunning solution.
Code:
import sys

def pad(n):
    sys.stdout.write(" " * n)

for a in range(0, 1):
    pad(3)
    for b in range(0, 1):
        sys.stdout.write("*")

    pad(3)
    print("")

    pad(2)
    for b in range(0, 3):
        sys.stdout.write("*")

    pad(2)
    print("")

    pad(1)
    for b in range(0, 5):
        sys.stdout.write("*")

    pad(1)
    print("")

    for b in range(0, 7):
        sys.stdout.write("*")

    print("")

    pad(1)
    for b in range(0, 5):
        sys.stdout.write("*")

    pad(1)
    print("")

    pad(2)
    for b in range(0, 3):
        sys.stdout.write("*")

    pad(2)
    print("")

    pad(3)
    for b in range(0, 1):
        sys.stdout.write("*")

    pad(3)
    print("")
Don't gag... I did. Tongue
No, jk... I will really try in a bit. xD

Hmm... actually I just came up with a compact solution. It follows all your rules, but I don't think it works the way you were intending. It's really funny how simple it is...
Code:
import sys

design = [
    "   *   ",
    "  ***  ",
    " ***** ",
    "*******",
    " ***** ",
    "  ***  ",
    "   *   "
]

for y in design:
    for x in y:
        sys.stdout.write(x)

    print("")

Biggrin Kudos to you for getting them both to work. I actually did more along the line of your first one until I realized I was printing '', and the rules state I can only use print for asterisks. But then again, it's kind of ambiguous, as you could interpret it as when you want to print an asterisk, you can only use a single one, but you are still able to print other things separately.


RE: Python Challenge - m0dem - 10-19-2015

(10-19-2015, 03:23 PM)God Wrote: Biggrin Kudos to you for getting them both to work. I actually did more along the line of your first one until I realized I was printing '', and the rules state I can only use print for asterisks. But then again, it's kind of ambiguous, as you could interpret it as when you want to print an asterisk, you can only use a single one, but you are still able to print other things separately.

Wait, you can only use print for astericks? I interpreted it as: you can only print one asterick at a time, and other characters don't matter how they are printed.


RE: Python Challenge - Nil - 10-19-2015

(10-19-2015, 03:30 PM)m0dem Wrote: Wait, you can only use print for astericks? I interpreted it as: you can only print one asterick at a time, and other characters don't matter how they are printed.

Yeah... Like I said, it's kind of ambiguous. The way I interpret it is I can only print single asterisks if I use the print statement. With that condition, I still haven't come up with a solution.

But if you used print statements for spaces and the like, that's fine. I'm sure the restriction to only use single asterisks is in my own head but I feel like I need to figure it out.


RE: Python Challenge - Rick - 11-14-2015

Dun it

Code:
for i in range(-3,4):
    spaces = ""
    ast = ""
    for x in range(0,abs(i)):
        spaces += " "
    for y in range(0,7-2*abs(i)):
        ast += "*"
    print(spaces,ast,spaces)

(I didn't read the post properly, he's an updated one)
Code:
for i in range(-3,4):
    spaces = ""
    ast = ""
    a = ""
    for x in range(0,abs(i)):
        print(" ", end="")
    for y in range(0,7-2*abs(i)):
        print("*", end="")
    for z in range(0,abs(i)+1):
        if z == abs(i):
            print(" ", end="\n")
        else:
            print(" ", end="")

The print function has a parameter that allows you to print in the same line again.


RE: Python Challenge - Megan - 12-12-2015

Code:
#!/usr/bin/env python
diamond = ["   *","  ***"," *****","*******"," *****","  ***","   *"]
var = 0

while var == 0:
    while var < 7:
        print diamond[var]
        var += 1

Whilst technically the first loop does absolutely nothing, it does actually count as a loop and so the second loop counts as the nested loop so yeah, 8 lines long, would love more challenges like this!