Cloud Stack Ninja

I am trying to take a string and print a descending triangle that removes one character until there are no characters left. For example if "hello" was inputed this would be the output:

hello
hell
hel
he
h

I am supposed to do it with both using with two separate functions, one using iteration and the other recursion so it outputs the triangle twice. This is what I have so far but I don't think it's very close.

    for i in range(len(text)):
    print(text[i:-1])

I also tried this but it just takes the entire string

    for i in range(len(text), 0, -1):
    for j in range(0,i):
        print(text, end="")
    print()


Read more here: https://stackoverflow.com/questions/64407941/inverted-triangle-of-inputed-text-python

Content Attribution

This content was originally published by srogers2000 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: