Blank no name
Blank no name

Reputation: 41

How can I increase the number of leading spaces for each new line printed?

I want to print the letter "H" 10 times (preferably in a loop) but for every new line that gets printed, the "H" has to move one space. How can I do this?

Here is my original code:

for a in range(0,10):
    b=" "
    b+="  "
    print(b+"H");

Upvotes: 1

Views: 2045

Answers (1)

Idos
Idos

Reputation: 15320

You can accomplish this simply by multiplying the index by the number of spaces you want:

>>> for i in range(10):
    print i * " " + "H"

H
 H
  H
   H
    H
     H
      H
       H
        H
         H

Upvotes: 3

Related Questions