Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Show diamond on screen using single loop

+1 vote
asked Feb 20, 2020 by Mirza

1 Answer

0 votes
answered Feb 21, 2020 by anonymous
n = int(input())
half = n//2
print((half)*" "+"*")
val = half-1
for i in range(1,n):
    if i<half+1:
        print((half-i)*" "+"*"+" "*(2*i-1)+"*")
    elif i>half+1:
        print((i-half-1)*" "+"*"+" "*(2*val-1)+"*")
        val -= 1
print((half)*" "+"*")
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.