I tries to write program that will be append to the list recursively
def string(times,char):
list=[]
list.append(char)
if times==0:
print(list)
else:
return [list] + string(times-1 ,char)
string(3,input('text'))
and when I start the code, I got error
TypeError: can only concatenate list (not "NoneType") to list
when times
is 0
your function prints the list but returns None
. That means [list] + string(times-1 ,char)
tries to concatenate None
to a list and that is not allowed.
Use return
instead of print
and this problem will be solved.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With