Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part 2 Lnai 8725

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448505, 978-3662448502

More Books

Students also viewed these Databases questions

Question

Answered: 1 week ago

Answered: 1 week ago

Question

3. Are our bosses always right? If not, what should we do?

Answered: 1 week ago

Question

2. What, according to Sergey, was strange at this meeting?

Answered: 1 week ago