Question: Write a Python function mega_digit that takes positive integer arguments N and k and returns the 'mega digit of P the number N repeated k

 Write a Python function mega_digit that takes positive integer arguments N

Write a Python function mega_digit that takes positive integer arguments N and k and returns the 'mega digit" of P the number N repeated k times. For example, if N-123 and k-3, then your function should return the mega digit of P-123 123 123 What is a "mega digit" you ask? Great question! If P is a single digit (1 S PS 9), then the mega digit of P is equal to P If P is more than one digit (P 2 10), then the mega digit of P is equal to the mega digit of the sum of the digits of P. Example 1: Let N-12. k = 2, Then p = 1212, and mega-digit(1212) = mega_digit(1 + 2 + 1 + 2) = mega-digit(6) = 6 Example 2: Let N-321, k- 3. Then P 321321321, and mega_digit(32 132 1321) = mega-digit(3 + 2 + 1 + 3 + 2 + 1 + 3 + 2 + 1) -mega digit(18)-mega digit(l + 8)mga_digit(9)-9 Notes: There are two visible test cases worth 0.5 points each, and five hidden test cases worth 1 point each. The integers N and k will satisfy 1 s N S 1016, and 1 sk S 10 The hidden test cases increase in the size of the inputs (but stay within the bounds given above). Getting the last 2 or 3 points in particular require at least a modest amount of effort to be invested in making your code efficient. For example: Result Test print mega_digit 12,2))6 print(mega_digit (321,3)) 9

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!