0

How to print a diamond shape in python

* ** *** ** *

6th Sep 2019, 5:56 PM
Rajat Srivastava
Rajat Srivastava - avatar
5 ответов
+ 3
#There is problem in this part: for l in range(1,4): for j in range(1,l+1): print('*',end="") #this whole code will execute(same each time) in each iteration of outermost loop as it is independent of variable i taken in outer loop. #try this for half diamond: for i in range(4,1,-1): for k in range(1,i-1): print(" ",end="") for l in range(0,4-i+1): print('*',end="") print(end='\n') #my suggestion would be to take odd number of stars in each row for a better output
6th Sep 2019, 7:52 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 1
show us your code to see you already tried
6th Sep 2019, 6:01 PM
Cat Sauce
Cat Sauce - avatar
0
for i in range(4,1,-1): for k in range(1,i-1): print(" ",end="") for l in range(1,4): for j in range(1,l+1): print('*',end="") print(end='\n')
6th Sep 2019, 6:02 PM
Rajat Srivastava
Rajat Srivastava - avatar
0
But this code is not working can you please tell the flaw
6th Sep 2019, 6:03 PM
Rajat Srivastava
Rajat Srivastava - avatar
0
This code is just for half diamond as I was just trying but failed
6th Sep 2019, 6:06 PM
Rajat Srivastava
Rajat Srivastava - avatar