A big change would be to improve the readability of the program.
Some changes I would make are:
- Add spacing between operators and make bracket style consistent (e.g.
((len(s)-1)//2)vs(len(s)-1)//2). - Convert calculations that are done multiple times (e.g. mid and lensize) into variables.
- Break down the large print statements into smaller and more readable sections; just making the code more verbose.
input_string = input("Enter string: ")
size = len(input_string)
mid = size // 2
for i in range(size):
if i == mid:
print(' ' * i + input_string[i])
elif i > mid:
left_space = ' ' * (size - 1 - i)
middle_space = ' ' * (2 * i - size + 1)
print(f"{left_space}{input_string[size-i-1]}{middle_space}{input_string[i]}")
else:
left_space = ' ' * i
middle_space = ' ' * (size - 2 * i - 2)
print(f"{left_space}{input_string[i]}{middle_space}{input_string[size-i-1]}")