python loops

Need help with your code? Post it here and we'll try our best to help.
MaC
Got Fofum
Posts: 296
Joined: Thu May 29, 2008 10:25 pm

python loops

Postby MaC » Sun Oct 05, 2008 9:16 pm

Code: Select all

def Vee(rows):
    for j in range(rows):
        for k in range(j):
            print "",
        print "**",
        for l in range(rows-j-1):
            print " ",
        print "**",
        print
       
def Hourglass(rows):
    for j in range(rows):
        for k in range(j):
            print " ",
        for l in range(2*rows-2*j-1):
            print "*",
        print
    for j in range(rows):
        for k in range(rows-j-1):
            print " ",
        for i in range(j+1):
            print "*",
        for l in range(j):
            print "*",
        print

Code: Select all

for the V it prints:
**         **
 **       **
  **     **
   **   **
    ** **
i need
**        **
 **      **
  **    **
   **  **
    ****
if i do for l in range(rows-j-2):
**        **
 **      **
  **    **
   **  **
    ** **
cuz of the comma

for the hourglass it prints
* * * * * * * * *
  * * * * * * *
    * * * * *
      * * *
        *
        *
      * * *
    * * * * *
  * * * * * * *
* * * * * * * * *
i need
* * * * * * * * *
  * * * * * * *
    * * * * *
      * * *
        *
      * * *
    * * * * *
  * * * * * * *
* * * * * * * * *

MaC
Got Fofum
Posts: 296
Joined: Thu May 29, 2008 10:25 pm

Postby MaC » Sun Oct 05, 2008 10:42 pm

i figured out the hourglass
for j in range(rows-1): in the second part of the code + some resetting to make it fit

User avatar
Centari
Is Kind Of A Big Deal
Posts: 882
Joined: Thu Aug 02, 2007 8:33 pm

Postby Centari » Tue Jan 13, 2009 12:31 pm

I like how you are the only person that posted in your own thread; and even better, you answered your own question!
Image

User avatar
Harness
Da Bumble
Posts: 2069
Joined: Mon Dec 10, 2007 6:13 pm

Postby Harness » Tue Jan 13, 2009 7:15 pm

lol
I type a bunch of shit then people go fuk themselves

MaC
Got Fofum
Posts: 296
Joined: Thu May 29, 2008 10:25 pm

Postby MaC » Tue Jan 13, 2009 9:21 pm

actually, i withdrew from the class and am currently changing my major...
BECAUSE NO ONE HELPED ME!!!!!

User avatar
Harness
Da Bumble
Posts: 2069
Joined: Mon Dec 10, 2007 6:13 pm

Postby Harness » Wed Jan 14, 2009 12:15 pm

Not out of depression due to the performance of your favorite football team?
I type a bunch of shit then people go fuk themselves

User avatar
dun dun dun... chips
Papes
Posts: 3287
Joined: Sat Oct 11, 2008 2:08 pm
Location: WOOOOOO
Contact:

Postby dun dun dun... chips » Wed Jan 14, 2009 3:24 pm

sorry mate. i couldve helped you with this one...
algorithms in cs is my strongsuit. python? not so much. but algorithms are algorithms.
if you still want to know the algorithm, i could probably work it out for you...


Return to “Code Monkeys”

Who is online

Users browsing this forum: No registered users and 1 guest