
- 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 for Check if all digits of a number divide it
In this article, we will learn about the solution and approach to solve the given problem statement.
Problem statement −Given a number n, find whether all digits of n divide it or not.
Here we will be checking that there is no 0 in the given number because this will give divide by zero exception and hence we must return no as an answer
Otherwise, we must check whether all digits are able to divide the number by using a temporary variable flag which allows declaring a check condition.
Now let’s have a look at the implementation −
Example
n=int(input()) flag=1 for i in str(n): if int(i)!=0 and n%int(i)==0: flag=1 else: flag=0 if(flag==1): print("Yes") else: print("No")
Output
Yes(22)
All the variables are declared in global scope as shown in the image below
Conclusion
In this article, we learnt about the approach to Check if all digits of a number divide it.
- Related Articles
- Check if all digits of a number divide it in Python
- 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 the frequency of all the digits in a number is same in Python
- C++ Program to check if a given number is Lucky (all digits are different)
- Python Program to check whether it is possible to make a divisible by 3 number using all digits in an array
- Python Program to Remove all digits before given Number
- Python Program for How to check if a given number is a Fibonacci number?
- Check if all bits of a number are set 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
- Program to find the sum of all digits of given number in Python
- Python Program to Check if a Number is a Perfect Number
- Python Program to Check if a Number is a Strong Number

Advertisements