464,640 Members | 1,101 Online
Need help? Post your question and get tips & solutions from a community of 464,640 IT Pros & Developers. It's quick & easy.

# How to format spaces in output?

 P: 5 Expand|Select|Wrap|Line Numbers 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. May 7 '12 #1

Expand|Select|Wrap|Line Numbers
1. dim = int(input("Enter the size of the diamond: "))
2. area = int(input('Enter the numer of times to be printed: '))
3.
4. def diamond(size, times):
5.     for j in range(times):
6.         for i in range(size):
7.             print (" "*(size-i) + "* " * i +" "*(size-i))*times
8.
9.         for i in range(size+1):
10.             print (" "*(i) + "* "*(size-i) + " "*(i))*times
11.
12. diamond(dim,area)
13.