How to print text diagonally from left to right in Python

2 Answers

0 votes
def print_text_diagonally(text):
    for i, ch in enumerate(text):
        print(" " * i + ch)
     
text = "Hello World"
 
print_text_diagonally(text)
  
  
'''
run:
  
H
 e
  l
   l
    o
       
      W
       o
        r
         l
          d
  
'''

 



answered Apr 5 by avibootz
edited Apr 6 by avibootz
0 votes
def print_text_diagonally(text):
    spaces = 0
  
    for ch in text:
        print(" " * spaces + ch)
        spaces += 1
     
 
text = "Hello World"
 
print_text_diagonally(text)
  
  
'''
run:
  
H
 e
  l
   l
    o
       
      W
       o
        r
         l
          d
  
'''

 



answered Apr 5 by avibootz
edited Apr 6 by avibootz
...