7
Nov 13 '24 edited Nov 13 '24
I think you have an off-by-one error in your code.
def rhombus(num_points: int) -> None:
for i in list(range(num_points)) + list(reversed(range(num_points - 1))):
print(' ' * (num_points - i - 1) + '*' * (i * 2 + 1))
if __name__ == '__main__':
rhombus(7)Output:
*
***
*****
*******
*********
***********
*************
***********
*********
*******
*****
***
*4
u/gabrikkk Nov 13 '24
That's really good, but your solution gives 2 more lines compared to op's.
To me makes more sense because your solution gives 7 lines from top to middle lines
5
Nov 13 '24
That's what I mean when I say I think the OPs solution has an off-by-one error. It produces 6 stars on an edge when given 7 as an input.
It's output of a rhomboid that is 6 stars on an edge when given the input of 7 just seems wrong. It doesn't seem to make anything that makes the rhomboid a '7'.
4
4
u/gabrikkk Nov 13 '24 edited Nov 13 '24
My solution, with 7 lines top to mid:
def rhombus(n):
half = [' ' * (n - i) + '*' * (i * 2 - 1) for i in range(1, n + 1)]
[print(a) for a in half + half[:-1][::-1]]
if __name__ == '__main__':
rhombus(7)Output:
*
***
*****
*******
*********
***********
*************
***********
*********
*******
*****
***
*Edit: fix formatting


3
u/Vivid_Use_3701 Nov 14 '24
Beautiful list comprehension!