Reputation: 9
def backwards_alphabet(curr_letter):
if curr_letter == 'a':
print(curr_letter)
else:
print(curr_letter)
prev_letter = chr(ord(curr_letter) - 1)
backwards_alphabet(prev_letter)
starting_letter = input()
print (backwards_alphabet(starting_letter)) #this is the code i wrote
The output includes "None" but I have no idea why. Image of output
Upvotes: 0
Views: 94
Reputation: 3113
The function print
takes a parameter - you are giving it the result of backwards_alphabet(starting_letter)
.
Since you aren't explicit about what backwards_alphabet()
returns - which you do would with by including return 'this is what I am returning'
, it will return None
by default.
So, you are calling print(None)
and it prints 'None'.
Since your function backwards_alphabet()
already has all of the printing within it, you don't want to do print(backwards_alphabet(...))
, you just want to call backwards_alphabet(...)
by itself.
Upvotes: 1