By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,400 Members | 903 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,400 IT Pros & Developers. It's quick & easy.

printing diamonds

P: 1
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.
Oct 11 '06 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 511
Post your code...
Oct 11 '06 #2

kudos
Expert 100+
P: 126
Do you need something like this?? this is more a hint than a complete solution

Expand|Select|Wrap|Line Numbers
  1. # print a diamond shape
  2.  
  3. c = 5;
  4. txt=""
  5. k = 0
  6.  
  7. for j in range(12):
  8.  txt=""
  9.  for i in range(12):
  10.   if (i<c-k) or (i>c+k):
  11.    txt+=" "
  12.   else:
  13.    txt+="*"
  14.  print txt  
  15.  if(j>c):
  16.   k-=1
  17.  elif(k<c):
  18.   k+=1
  19.  else:
  20.   k=c
  21.  
-Kudos


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.
Oct 12 '06 #3

Post your reply

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