Question: Python 3: Write a function oneSum which takes one input, n , and finds the sum: 1 + 11 + 111 + 1111 + ...
Python 3: Write a function oneSum which takes one input, n, and finds the sum:
1 + 11 + 111 + 1111 + ... up to n digits of 1.
For example:
>>> print (oneSum( 1 ))
1
Which is 1 = 1.
>>> print (oneSum( 2 ))
12
Which is 1 + 11 = 12.
>>> print (oneSum( 3 ))
123
Which is 1 + 11 + 111 = 123.
Hint: think about each element of the sum (1, 11, 111, for example) represented as a sum of powers of 10:
111 = 10^0 + 10^1 + 10^2 = 1 + 10 + 100
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
