import sys num_steps = int(sys.argv[1]) for x in range(1, num_steps+1): print (" " * (num_steps - x), "#" * x ) 

enter image description here

  • What does "extra" mean? - Serg4356
  • The all-knowing Google showed this: x = x.lstrip () - If left. From two sides - x.strip () - vikttur
  • the sixth line shows that there is an extra space on the left) it needs to be removed - andrewpailyk
  • 2
    hint: compare print('', 'a') and print('', 'a', sep='') - MaxU
  • one
    understand, thank you very much - andrewpailyk

1 answer 1

print(x, y) inserts a default space between x and y . Therefore, the space remains even when x empty. Replace the comma with a + to print as one line: print(x + y) .


for people attracted here by the title of the question - not relevant to the task in the question itself:

You can use s = s.lstrip() to remove all spaces at the beginning of a line:

 >>> ' \na \n'.lstrip() 'a \n'