this is what Ii wrote so far but it is not the correct output
def characters(char):
numb=ord(char)
while numb>ord('a'):
print chr(numb),
numb=numb-1
return
I want the this output:
characters('h')
g f e d c b a
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Whenever you design a recursive function, the first thing you want to ask yourself is: how does the algorithm terminate? 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:
(If you don’t know what the Python functions
ordandchrdo, look them up in the interactive interpreter usinghelp(ord)andhelp(chr).)