How to format spaces in output?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • growthndevlpmnt
    New Member
    • May 2012
    • 5

    How to format spaces in output?

    Code:
    dim = int(input("Enter the size of the diamond: "))
    area = int(input('Enter the numer of times to be printed: '))
    
    def diamond(size, times):
    ***for j in range(times):
    *******for i in range(size):
    ***********print (" "*(size-i) + "* " * i)*times
    
    *******for i in range(size+1):
    ***********print (" "*(i) + "* "*(size-i))*times
    
    diamond(dim,area)
    Please help me fix my formatting issue. This code should print a n by n square of stars that are m asterisks wide. The first column of stars is perfect but each progressive column gets worse and worse until the start running into each other. Thanks.
  • Smygis
    New Member
    • Jun 2007
    • 126

    #2
    Code:
    dim = int(input("Enter the size of the diamond: "))
    area = int(input('Enter the numer of times to be printed: '))
     
    def diamond(size, times):
        for j in range(times):
            for i in range(size):
                print (" "*(size-i) + "* " * i +" "*(size-i))*times
     
            for i in range(size+1):
                print (" "*(i) + "* "*(size-i) + " "*(i))*times
     
    diamond(dim,area)

    Comment

    • growthndevlpmnt
      New Member
      • May 2012
      • 5

      #3
      Thank you SO much. It's always the little things. #embarrassment

      Comment

      Working...