printing diamonds

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dragonwebz
    New Member
    • Oct 2006
    • 1

    #1

    printing diamonds

    hey, I'm new here but heard a lot about some new stuff I could learn on here. However I'm kinda stuck on a program thats supposed to print a diamond depend what the user inputs as a width. Yes, I have seen this problem worked out in C++ before and I have spent a few hours trying to convert it into Python however I just can't seem to get the 'for' loop right. Any help on this part would be greatly appreciated.
  • ghostdog74
    Recognized Expert Contributor
    • Apr 2006
    • 511

    #2
    Post your code...

    Comment

    • kudos
      Recognized Expert New Member
      • Jul 2006
      • 127

      #3
      Do you need something like this?? this is more a hint than a complete solution

      Code:
      # print a diamond shape
      # 
      
      c = 5;
      txt=""
      k = 0
      
      for j in range(12):
       txt=""
       for i in range(12):
        if (i<c-k) or (i>c+k):
         txt+=" "
        else:
         txt+="*"
       print txt  
       if(j>c):
        k-=1
       elif(k<c):
        k+=1
       else:
        k=c
      -Kudos


      Originally posted by dragonwebz
      hey, I'm new here but heard a lot about some new stuff I could learn on here. However I'm kinda stuck on a program thats supposed to print a diamond depend what the user inputs as a width. Yes, I have seen this problem worked out in C++ before and I have spent a few hours trying to convert it into Python however I just can't seem to get the 'for' loop right. Any help on this part would be greatly appreciated.

      Comment

      Working...