Take a char and print out from char to 'a' and revers it should be recursive?

I.e. , what's the base case? In your example, the algorithm should stop printing characters after the letter 'a' is printed, so that's your base case Next, you have to ask how to get to the base case from your starting case.

That's pretty easy: you want to print the previous character until you reach the base case. (A character is essentially just an integer, so that means you want to subtract one from the character and print it as a string.) Putting that all together, I got: def print_reverse(ch): print ch, if ch > 'a': print_reverse(chr(ord(ch)-1)) else: print # New line print_reverse('h') (If you don't know what the Python functions ord and chr do, look them up in the interactive interpreter using help(ord) and help(chr) ).

I.e. , what's the base case? In your example, the algorithm should stop printing characters after the letter 'a' is printed, so that's your base case.

Next, you have to ask how to get to the base case from your starting case. That's pretty easy: you want to print the previous character until you reach the base case.(A character is essentially just an integer, so that means you want to subtract one from the character and print it as a string.) Putting that all together, I got: def print_reverse(ch): print ch, if ch > 'a': print_reverse(chr(ord(ch)-1)) else: print # New line print_reverse('h') (If you don't know what the Python functions ord and chr do, look them up in the interactive interpreter using help(ord) and help(chr). ).

Thx ... it really helped... – user531225 Dec 6 '10 at 23:13.

Your function should be designed to call itself if it has to be recursive: def recurse_chars_down(char): if char >> recurse_chars_down('h') h g f e d c be a.

Recursive : def character(char): print(char) character(chr(ord(char)-1)) return.

Ok... check the latest condition... just like Frederic does... – Matthieu Dec 6 '10 at 23:02.

Def characters(char): if char == 'a': return '' next_char = chr(ord(char)-1) return next_char+' '+characters(next_char) >>> characters('h') 'g f e d c be a.

Thanks :) ..... – user531225 Dec 6 '10 at 23:15.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions