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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!