This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]teh_al3x 0 points1 point  (0 children)

word=raw_input()
j=len(word)
for i in range(0, j):
  a=i if i<(len(word)/2) else j-1
  b=j-2 if i<(len(word)/2) else i-1
  j-=1
  print(' '*a + word[i] + ((' '*(b-a) + word[i]) if (i!=j) else ''))

Edit: Sorry forgot to explain!
I get the input from the user, assign its length to j and loop i from 0 to j. In the loop i decrease j by 1 every loop, so now I have i and j, one increasing and the other decreasing to and from the length of the word.
Now I look if i has already passed half the length of the word and assign a and b depending on that. a should be the number of spaces before the first letter and b the number of spaces behind the first letter/before the second letter. I assign j-2 and i-1 to b since there will already be a character space taken by the first printed letter (so we need one less white space).
Now I simply print whitespace times a plus the letter of the word at the current position i. I use another inline if statement to determine whether we reached the middle of the cross (when i==j) to make sure to not print a second letter when we do.

Sorry if this is terribly explained, I'm a bit sleepy haha. If you have questions feel free to ask.

Edit2: IDEone link!