chevron_left chevron_right
Login Register invert_colors photo_library
Stay updated and chat with others! - Join the Discord!
Thread Rating:
  • 0 Vote(s) - 0 Average


Bronze Python Challenge filter_list
Author
Message
Python Challenge #1
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...luzuy2.png

Reply

RE: *Simple* Python Challenge #2
>simple
>couldn't solve it

pick one

OT: The image isn't loading for me.

Reply

RE: *Simple* Python Challenge #3
(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.

Reply

RE: Python Challenge #4
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("")
(This post was last modified: 10-19-2015, 04:51 AM by m0dem.)

[+] 1 user Likes m0dem's post
Reply

RE: Python Challenge #5
(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.

[+] 2 users Like Eclipse's post
Reply

RE: Python Challenge #6
(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.

Reply

RE: Python Challenge #7
(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.

Reply

RE: Python Challenge #8
(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.

Reply

RE: Python Challenge #9
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.

[+] 2 users Like Rick's post
Reply

RE: Python Challenge #10
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!
[Image: 9JVyFsC.png]
Sig by @Symadox

XMPP: Mi5@DukGo.com

Reply






Users browsing this thread: 1 Guest(s)