+ 5
1+12+123+1234+....
Using recursion in Python
15 Answers
+ 11
try this
def totalNum(n):
n = [str(i) for i in range(1,n+1)]
return int("".join(n))
def func(n):
if num == 0:
return 0
return totalNum(n) + func(n-1)
# 123 + 12 + 1
print(func(3))
>>>
136
try understanding this code.
hope you understand how to use recursion effectively.
+ 10
How can i find the answer
+ 2
Here is my C++ solution as a hint. You have to convert it into python code on your own đ.
https://code.sololearn.com/ca2RTcEtnFuL/?ref=app
+ 1
Your attempt?show what you have done ,and we may help you further
and mention the language name in tags where you have put o
0
It needs to be a finite rather than an infinite addition.
0
Up-to n terms means if the input is greater it may cause recursive error in python.
- 1
Upto n terms
- 1
Yes by using recursive function
- 1
a=0
n=int(input())
for i in range(1,n+1):
a=a+int(str(i)*n)
if n>0:
n=n-1
print(a)
Simplest code
- 1
I said using recursion