Name Display on Diagonal (Top to Bottom)

-3

I have to read a name and display it diagonally, ie from top to bottom.

But I am not able to develop the correct logic, I have come to this:

nome = input('Digite o seu nome: ')
tamanho = len(nome)

for nome in range(tamanho):
    print(nome)

But it returns only the count of the size of the String, and I want it instead of the count to display its letter of the name that the user typed.

    
asked by anonymous 17.12.2018 / 01:36

1 answer

4

The range(n) function will generate a sequence of integers [0, n [ which is not very useful for you in this case. If I understood correctly, you need to print the name entered on the "diagonal", something like:

>>> Insira seu nome: anderson
a
 n
  d
   e
    r
     s
      o
       n

That is, you increase the number of blanks before each letter. The first letter, at index 0, has zero spaces; the second, at index 1, has a space; and so on. So for you to get the letter and its index inside the name you should use the enumerate function:

nome = input('Insira seu nome:')

for indice, letra in enumerate(nome):
    print(' ' * indice + letra)

And you will have the presentation of the name as exemplified.

    
17.12.2018 / 02:28