- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Program to find sum of digits in base K using Python

Suppose we have a number n in decimal number system (base 10) have another value k, we have to find the sum of the digits of n after converting given number n from base 10 to base k. When we calculate digit sum, we will consider each digit as decimal (base 10) number.

So, if the input is like n = 985 k = 8, then the output will be 12 because the number 985 in octal is 1731, so the digit sum is 1+7+3+1 = 12.

To solve this, we will follow these steps −

ans := 0

while n >= k, do

ans := ans + n mod k

n := quotient of n/k

ans := ans + n

return ans

Let us see the following implementation to get better understanding −

## Example

def solve(n, k): ans = 0 while n>=k: ans = ans + n%k n = n//k ans = ans+n return ans n = 985 k = 8 print(solve(n, k))

## Input

985,8

## Output

True

- Related Questions & Answers
- Program to find minimum digits sum of deleted digits in Python
- Program to find sum of rectangle whose sum at most k in Python
- Java Program to Find Sum of Digits of a Number using Recursion
- Program to Find K-Largest Sum Pairs in Python
- Program to find the sum of largest K sublist in Python
- Program to find max number of K-sum pairs in Python
- Program to find the sum of all digits of given number in Python
- C# program to find the sum of digits of a number using Recursion
- Python Program to Find the Sum of Digits in a Number without Recursion
- 8085 program to find sum of digits of 8 bit number
- 8086 program to find sum of digits of 8 bit number
- Program to find sum of digits until it is one digit number in Python
- Program to find sum of digits that are inside one alphanumeric string in Python
- Program to find number of distinct combinations that sum up to k in python
- Program to find minimum largest sum of k sublists in C++

Advertisements