Monday, 12 August 2013

Remove trailing white space in python 3

Remove trailing white space in python 3

Having bit of trouble with a program i made. i am getting it to display a
diamond but i have a problem, here is my code:
a = input("Enter width: ")
a = int(a)
b = a
for i in range(a):
i = i + 1
b = a - i
print(" " * b, "* " * i)[:-1] # HERE The slice doesn't work
for i in range(a):
i = i + 1
b = a - i
print(" " * i, "* " * b)[:-1] # AGAIN here
As you can see lines 7 and 11 don't work. I would like to just remove the
trailing white space with a slice function and it says i can't do that.
Please help

No comments:

Post a Comment