Skip to content Skip to sidebar Skip to footer

Print User Input In "cascade" Of Characters?

I am trying to create code that gathers a user's first and last name (input order is last, first) and prints it first, last in a cascading way: J o h n S

Solution 1:

You can write a generic function, like the one shown below and reuse for your strings.

def cascade_name(name):
    for i, c in enumerate(name):
        print '\t'*(i+1), c

output:

>>> cascade_name("foo")
    f
        o
            o

In your case you would do:

last = raw_input('enter your last name:')
first= raw_input('enter your first name:')
cascade_name(last)
cascade_name(first)

Post a Comment for "Print User Input In "cascade" Of Characters?"