Skip to content

Commit 7b1ee46

Browse files
Merge pull request #160 from LaunchCodeEducation/diamond-function
updated diamond function
2 parents cf55509 + e7193a8 commit 7b1ee46

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

content/functions/exercises/_index.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,17 @@ You will find the starter code in `data-analysis-projects/functions/exercises/fu
274274
```python {linenos=table}
275275
def make_diamond(height):
276276
diamond = ""
277-
triangle = make_isosceles_triangle(height)
278-
diamond += triangle[:-1]
279-
for i in range(len(triangle)-1, -1, -1):
280-
diamond += triangle[i]
277+
278+
for i in range(height):
279+
spaces = " " * (height - i - 1)
280+
hash = "#" * (2 * i + 1)
281+
diamond += spaces + hash + "\n"
282+
283+
for i in range(height - 2, -1, -1):
284+
spaces = " " * (height - i - 1)
285+
hash = "#" * (2 * i + 1)
286+
diamond += spaces + hash + "\n"
287+
281288
return diamond
282289

283290
print(make_diamond(5))

0 commit comments

Comments
 (0)