Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
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