Question: Write a function mode_digit that takes an integer number n and returns the digit that appears most frequently in that number. The given number may

Write a function mode_digit that takes an integer number n and returns the digit that appears most frequently in that number. The given number may be positive or negative, but the most frequent digit returned should always be non-negative. If there is a tie for the most frequent digit, the digit with the greatest value should be returned.

To receive full credit, your solution must not use any nested loops or recursion (if you don't know what that is, you aren't using it), and you must have no more than 4 if/elif/else branches. You are allowed to use extra storage to solve this problem. Here are some example calls

mode_digit(12121) # 1 mode_digit(0) # 0 mode_digit(-122) # 2 mode_digit(1211232231) # 2

Hint

If you want to create a list with N zeroes in, you can write the line

a = [0] * N, # If N = 3, then a = [0, 0, 0]

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!