How would you define a recursive function that asks the user for a string and prints it from the outside in. For example, 123456 would print as 162534. Any help would be appreciated.
jozz3
0
Light Poster
Recommended Answers
Jump to PostWhat do you have so far?
To start you are going index the first and last in the method.
str = '123456' str[0] #index the first str[-1:]#index the last
Then just build a simple recursive method to solve.
Post your code if you have any …
Jump to Postdoes it have to be recursive?
something like this (I haven't tested this code,
just typed it down really quickly)def print_out_in(text): if len(text) % 2: end = ((len(text) - 1)/2) + 1 for x in range(1,end): print text[x] print text[(-1)*x] print text[end+1] else: end = len(text)/2 …
All 5 Replies
tbone2sk
14
Junior Poster in Training
jcao219
18
Posting Pro in Training
jcao219
18
Posting Pro in Training
woooee
814
Nearly a Posting Maven
jozz3
0
Light Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.