
- 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 the count of divisors is even or odd
In this article, we will learn about the solution and approach to solve the given problem statement.
Problem statement −Given a number “n”, find its total number of divisors is even or odd.
In this approach, we will be finding all the divisors and checking that the count of divisors is even or odd.
The implementation is given below −
Example
import math def countDivisors(n) : count = 0 # calculating all the divisors root=int(math.sqrt(n))+2 for i in range(1, root) : if (n % i == 0) : # If divisors are equal,increment count by one Otherwise increment count by 2 if( n // i == i) : count = count + 1 else : count = count + 2 if (count % 2 == 0) : def countDivisors(n) : count = 0 # calculating all the divisors root=int(math.sqrt(n))+2 for i in range(1, root) : if (n % i == 0) : # If divisors are equal,increment count by one Otherwise increment count by 2 if( n // i == i) : count = count + 1 else : count = count + 2 if (count % 2 == 0) : print("Even") else : print("Odd") # Driver program to test above function */ print("The count of divisor: ") countDivisors(100) print("Even") else : print("Odd") # Driver program to test above function */ print("The count of divisor: ") countDivisors(100)
Output
120 No
All the variables are declared in global scope as shown in the image below
Conclusion
In this article, we learned about the approach to Check if the count of divisors is even or odd of a given number.
- Related Articles
- Check if count of divisors is even or odd in Python
- C Program to Check if count of divisors is even or odd?
- Java Program to check if count of divisors is even or odd
- PHP program to check if the total number of divisors of a number is even or odd
- How to Check if a Number is Odd or Even using Python?
- C++ Program to Check Whether Number is Even or Odd
- 8085 program to check whether the given number is even or odd
- Java Program to Check Whether a Number is Even or Odd
- Haskell Program to Check Whether a Number is Even or Odd
- Check whether the length of given linked list is Even or Odd in Python
- C++ program for the Array Index with same count of even or odd numbers on both sides?
- Check whether given floating point number is even or odd in Python
- Program to check if a number is Positive, Negative, Odd, Even, Zero?
- Check whether product of 'n' numbers is even or odd in Python
- Python Program for Odd-Even Sort / Brick Sort

Advertisements