Question: Python code We define super digit of an integer x using the following rules: Given an integer, we need to find the super digit of
Python code
We define super digit of an integer x using the following rules:
Given an integer, we need to find the super digit of the integer.
If x has only digit, then its super digit is x
Otherwise, the super digit of x is equal to the super digit of the sum of the digits of x
For example, the super digit of will be calculated as:
superdigit
superdigit
superdigit
superdigit
Example
n
k
The number p is created by concatenating the string n k times so the initial p
superDigitp superDigit
superDigitp superDigit
superDigitp superDigit
All of the digits of p sum to The digits of sum to is only one digit, so it is the super digit.
Function Description
Complete the function superDigit in the editor below. It must return the calculated super digit as an integer.
superDigit has the following parameters:
string n: a string representation of an integer
int k: the times to concatenate n to make p
Returns
int: the super digit of n repeated k times
Input Format
The first line contains two space separated integers, n and k
Constraints
n
k
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
