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
RE: Python Challenge #11
(12-12-2015, 01:22 PM)Megan Wrote:
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!

For gosh sake, use Python 3+! Wink2
I'll let this one pass because I like it, but... technically wouldn't this be printing multiple asterisks each iteration breaking one of the rules? What do you think?

Reply

RE: Python Challenge #12
(12-12-2015, 07:59 PM)God Wrote: For gosh sake, use Python 3+! Wink2
I'll let this one pass because I like it, but... technically wouldn't this be printing multiple asterisks each iteration breaking one of the rules? What do you think?

Well technically it's printing them in a loop, yeah it does break the rule you specified about single printing.

So I will re-do the challenge and make it print singularly.

Code:
#!/usr/bin/env python
symbol = "*"
var = 1
rnd = 0
tim = 0

while var == 1:
    while tim < 9:
        if var == 1 and rnd == 0:
            print "   " + symbol
            var += 2
            tim += 1
        elif var == 3 and rnd == 0:
            print "  " + symbol * var
            var += 2
            tim += 1
        elif var == 5 and rnd == 0:
            print " " + symbol * var
            var += 2
            tim += 1
        elif var == 7 and rnd == 0:
            print symbol * var
            rnd = 1
            tim += 1
        elif var == 7 and rnd == 1:
            var -= 2
            tim += 1
            print " " + symbol * var
        elif var == 5 and rnd == 1:
            var -= 2
            tim += 1
            print "  " + symbol * var
        elif var == 3 and rnd == 1:
            var -= 2
            tim += 1
            print "   " + symbol * var
            exit()

There we go @GOD I managed to adhere to the only printing it once rule.
[Image: 9JVyFsC.png]
Sig by @Symadox

XMPP: Mi5@DukGo.com

[+] 1 user Likes Megan's post
Reply

RE: Python Challenge #13
(12-12-2015, 08:03 PM)Megan Wrote: Well technically it's printing them in a loop, yeah it does break the rule you specified about single printing.

So I will re-do the challenge and make it print singularly.

Code:
#!/usr/bin/env python
symbol = "*"
var = 1
rnd = 0
tim = 0

while var == 1:
    while tim < 9:
        if var == 1 and rnd == 0:
            print "   " + symbol
            var += 2
            tim += 1
        elif var == 3 and rnd == 0:
            print "  " + symbol * var
            var += 2
            tim += 1
        elif var == 5 and rnd == 0:
            print " " + symbol * var
            var += 2
            tim += 1
        elif var == 7 and rnd == 0:
            print symbol * var
            rnd = 1
            tim += 1
        elif var == 7 and rnd == 1:
            var -= 2
            tim += 1
            print " " + symbol * var
        elif var == 5 and rnd == 1:
            var -= 2
            tim += 1
            print "  " + symbol * var
        elif var == 3 and rnd == 1:
            var -= 2
            tim += 1
            print "   " + symbol * var
            exit()

There we go @GOD I managed to adhere to the only printing it once rule.
Nice! What is the point of exit()? Is that just if you're running through the interpreter?

[+] 1 user Likes Nil's post
Reply

RE: Python Challenge #14
(12-12-2015, 08:49 PM)God Wrote: Nice! What is the point of exit()? Is that just if you're running through the interpreter?

the loop doesn't break properly and I cba to fix it when I'm this tired so it's a dirty way to end the python script.
[Image: 9JVyFsC.png]
Sig by @Symadox

XMPP: Mi5@DukGo.com

Reply

RE: Python Challenge #15
(12-12-2015, 08:52 PM)Megan Wrote: the loop doesn't break properly and I cba to fix it when I'm this tired so it's a dirty way to end the python script.

Oh okay. It actually bothered me because when I run the script it automatically brings up a prompt asking me to kill the program, and clicking yes ends the shell.

Reply

RE: Python Challenge #16
(12-12-2015, 08:55 PM)God Wrote: Oh okay. It actually bothered me because when I run the script it automatically brings up a prompt asking me to kill the program, and clicking yes ends the shell.

haha yeah, I just use linux terminals so it exits for me.
[Image: 9JVyFsC.png]
Sig by @Symadox

XMPP: Mi5@DukGo.com

Reply






Users browsing this thread: 1 Guest(s)