Context:
Write a program to print the output for the given input(Example is given in comments of my code). String is of odd length.
I would be grateful if anyone could give feedback on my following code. The code runs correctly but I want to know if there can be any potential improvements in terms of code style and optimization.
s=input("enter string") #take s="12345" for example #output should be: # 1 5 # 2 4 # 3 # 2 4 # 1 5 for i in range(0,len(s)): # loop runs 5 times from index 0 to index 4 if i==((len(s)-1)//2): #first condition prints the center of pattern print(" "*i,s[i]) #leading 2 spaces print 3 elif i>(len(s)-1)//2: # second condition prints the characters above the center 3 print(" "*(len(s)-1-i),s[len(s)-i-1]," "*(i-(len(s)-i)-1)+s[i]) # 1 5 # 2 4 # 3 else: print(" "*i,s[i]," "*(len(s)-(2*(i+1))-1)+s[len(s)-i-1]) # else statement prints characters below the center # in reversed order # 3 # 2 4 # 1 5