Question
Python 3: Write a function n Sum which takes one input, n , and finds the sum: n + nn + nnn + nnnn +
Python 3: Write a function nSum which takes one input, n, and finds the sum:
n + nn + nnn + nnnn + ... up to n digits of n.
For example:
>>> print (nSum( 1 ))
1
Which is 1 = 1.
>>> print (nSum( 2 ))
24
Which is 2 + 22 = 24.
>>> print (nSum( 3 ))
369
Which is 3 + 33 + 333 = 369.
>>> print (nSum( 4 ))
4936
Which is 4 + 44 + 444 + 4444 = 4936
>>> print (nSum( 5 ))
61725
Which is 5 + 55 + 555 + 5555 + 55555 = 61725.
Hint: think about each element of the sum (3, 33, 333, for example) represented as a sum of powers of 10:
333 = 3 * 10^0 + 3 * 10^1 + 3 * 10^2 = 3 + 30 + 300
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started