1

I am new to python. I recently created a grid in python to test myself, which worked out brilliantly.

The reason why the answers given in the other questions are not useful for me is because the code which is given to them is much more complex and since I am new to coding, I find it quite difficult to understand it. Also the diamonds miss one of the layers which I have.

I thought I would attempt to create a diamond something which would look like:

Click on the link to view

Please could someone show me what to do next - as I am quite confused.

D= int(input("Please enter the width of the diamond:"))

for x in range():

    for y in range(height):
        print('*', end=' ')
    print()

I have tried multiple things but it is not working. Please can someone help me :)

Thanks to everyone that has answered my question. Could Someone just answer me this : If I wanted the diamond to have a width no more than 30 and the user inputted 35. How would I stop it from even printing thanks

  • If none of the answers at the linked page help you, please edit your question to explain why they don't work for you, and I'll be happy to re-open your question. – PM 2Ring Nov 08 '17 at 15:26
  • I've added it to the question - "The reason why the answers given in the other questions are not useful for me is because the code which is given to them is much more complex and since I am new to coding, I find it quite difficult to understand it. Also the diamonds miss one of the layers which I have." –  Nov 08 '17 at 15:33
  • 1
    Dont just look at the accepted answer, further below are perfectly fine ways too that are not much more complicated than your code here. E.g. by `Reblochon Masque` – voiDnyx Nov 08 '17 at 15:36
  • D= int(input("Please enter a number for the width of the Diamond:")) for i in range(D-1): print((D-i) * ' ' + (1*i+1) * '*') for i in range(D-1, -1, -1): print((D-i) * ' ' + (1*i+1) * '*') –  Nov 08 '17 at 15:44
  • This is what I have currently. It only does half a diamond? –  Nov 08 '17 at 15:45
  • Here's a better one, with fairly readable code that works properly in Python 3. You just need to pass it an input of 4. https://stackoverflow.com/a/18203306/4014959 – PM 2Ring Nov 08 '17 at 15:45
  • It's _really_ hard to read multi-line Python code in comments because the indentation gets lost. But anyway, your latest code puts out the right number of stars per row, but it squishes them together. You need spaces between the stars in each row. – PM 2Ring Nov 08 '17 at 15:49
  • Thank you guys - I have done it now. Thank you for putting me in the right direction. I really appreciate it !!! –  Nov 08 '17 at 15:52
  • Sorry just a quick question. If I wanted the diamond to have a width no more than 30 and the user inputted 35. How would I stop it from even printing thanks –  Nov 08 '17 at 16:05
  • There are a couple of ways to handle that. A simple way is to test the number as soon as you've read & converted it to an int, and if it's too big, exit from the script. So immediately after the input line, do `if wid > 30:` `exit()` . For fancier ways of handling input, please see [Asking the user for input until they give a valid response](https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response) – PM 2Ring Nov 08 '17 at 16:08

0 Answers0