By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,640 Members | 1,101 Online
Bytes IT Community
+ Ask a Question
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
  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)*times
  8.  
  9. *******for i in range(size+1):
  10. ***********print (" "*(i) + "* "*(size-i))*times
  11.  
  12. 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

✓ answered by Smygis

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.  

Share this Question
Share on Google+
2 Replies

Smygis
100+
P: 126
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.  
May 7 '12 #2

P: 5
Thank you SO much. It's always the little things. #embarrassment
May 15 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.