
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python Program to check whether it is possible to make a divisible by 3 number using all digits in an array
In this article, we will learn about the solution and approach to solve the given problem statement.
Problem statement
Given an array input of integers, we need to find whether it’s possible to make an integer using all the digits available in these numbers such that it would be divisible by 3.
Here we will generate a function that will take two arguments namely the array of integers and the length of the array.
The implementation given below works on the concept from the mental mathematics. Here we observe that a number is divisible by 3 if the sum of the digits are divisible by 3.
Now let’s see the implementation below −
Example
def isPossibleToMakeDivisible(arr, n): remainder = 0 for i in range (0, n): remainder = (remainder + arr[i]) % 3 return (remainder == 0) # main() arr = [33,40,90] n = 3 if (isPossibleToMakeDivisible(arr, n)): print("Yes") else: print("No")
Output
No
All variables and functions are declared in global scope as shown in the figure below.
Conclusion
In this article, we learnt about the approach to find whether it is possible to make a divisible by 3 number using all digits in an array.
- Related Articles
- Java Program to check whether it is possible to make a divisible by 3 number using all digits in an array
- C/C++ Program to check whether it is possible to make a divisible by 3 number using all digits in an array?
- C/C++ Program to check whether it is possible to make the divisible by 3 number using all digits in an array?
- Possible to make a divisible by 3 number using all digits in an array in C++
- Number of digits to be removed to make a number divisible by 3 in C++
- Check whether it is possible to make both arrays equal by modifying a single element in Python
- Check whether product of digits at even places of a number is divisible by K in Python
- Check whether sum of digits at odd places of a number is divisible by K in Python
- C Program to check if a number is divisible by sum of its digits
- C Program to check if a number is divisible by any of its digits
- Python Program for Check if all digits of a number divide it
- C Program to Check if all digits of a number divide it
- PHP program to check if all digits of a number divide it
- Java Program to check if all digits of a number divide it
- Check if all digits of a number divide it in Python
