How can I print letters down below
Question:
Answers:
You can implement your own backwards counter with range
. zip
that with the original string and you have your count.
>>> text = "ahoj"
>>> for i, c in zip(range(len(text),0,-1), text):
... print(" "*i + c)
...
a
h
o
j
Or, use enumerate to get indexes and do a little subtraction
>>> for i,c in enumerate(text):
... print(" "*(len(text)-i) + c)
...
a
h
o
j
I’ve two solutions for this, maybe this is more readable?
slovo = input("Zadaj slovo: ")
max_spaces = len(slovo) - 1
for i, char in enumerate(slovo):
print(" " * (max_spaces - i) + char)
spaces = len(slovo) - 1
for char in slovo:
print(" " * spaces + char)
spaces -= 1
Output:
Zadaj slovo: ahoj
a
h
o
j
a
h
o
j
You can implement your own backwards counter with range
. zip
that with the original string and you have your count.
>>> text = "ahoj"
>>> for i, c in zip(range(len(text),0,-1), text):
... print(" "*i + c)
...
a
h
o
j
Or, use enumerate to get indexes and do a little subtraction
>>> for i,c in enumerate(text):
... print(" "*(len(text)-i) + c)
...
a
h
o
j
I’ve two solutions for this, maybe this is more readable?
slovo = input("Zadaj slovo: ")
max_spaces = len(slovo) - 1
for i, char in enumerate(slovo):
print(" " * (max_spaces - i) + char)
spaces = len(slovo) - 1
for char in slovo:
print(" " * spaces + char)
spaces -= 1
Output:
Zadaj slovo: ahoj
a
h
o
j
a
h
o
j