# Check if Decimal representation of an Octal number is divisible by 7 in Python

Suppose we have one octal number. We have to check whether the decimal representation of the given octal number is divisible by 7 or not.

So, if the input is like n = 61, then the output will be True as the decimal representation of 61 is 6*8 + 1 = 48 + 1 = 49 which is divisible by 7.So, if the input is like n = 61, then the output will be True as the decimal representation of 61 is 6*8 + 1 = 48 + 1 = 49 which is divisible by 7.

To solve this, we will follow these steps −

• sum := 0
• while num is non-zero, do
• sum := sum + (num mod 10)
• num := quotient of (num / 10)
• if sum mod 7 is same as 0, then
• return True
• return False

Let us see the following implementation to get better understanding −

## Example

Live Demo

def solve(num):
sum = 0
while num:
sum += num % 10
num = num // 10
if sum % 7 == 0 :
return True
return False
num = 61
print(solve(num))

## Input

61

## Output

True

Updated on: 30-Dec-2020

112 Views 