Support our Blind Hand Charity by donating at 9818291723. Your contribution has the potential to bring about significant positive change for humanity.

Search This Blog

Saturday, September 9, 2023

TOWER OF HANOI

l=[]

t=-3

p=0

c=int(input("Enter range of elements = "))

for i in range(0,c):

    n=int(input("Enter the digit = "))

    l.append(n)

l.sort()

print()

for i in range(0,c):

    t+=2

    s=(t+1)//2

    for k in range(c-1,i,-1):

        print(' ',end="")

    for j in range(0,t+2):

        if s==0:

            p=1

        print(l[s],end="")

        if s>0 and p!=1:

            s-=1

        else:

            s+=1

    p=0

    print()

OUTPUT