I have just started to program in python, and I am stuck with a problem regarding recursion.
The program seems to compile, however, the print output is not shown.
Here is the program:
print 'type s word'
s = raw_input()
print 'enter a number'
n = raw_input()
def print_n(s, n):
if n<=0:
return
print s
print_n(s, n-1)
the output i get is:
xxxx@xxxx-Satellite-L600:~/Desktop$ python 5exp3.py
type s string
hello
add the number of recursions
4
xxxx@xxxx-Satellite-L600:~/Desktop$
What is wrong, and how can I get the program to show an output?
raw_inputreturns strings which you must convert to integers withint.return print_n(s, n-1), when calling the function recursively, though it might not cause any problem in this case, but keep that in mind for future uses.None.