- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
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
Advertisements