Python Program to Check a Number is a Pronic Number

Write a Python program to check a number is a Pronic number or not using a while loop. For example, if a number is equal to the product of two consecutive numbers, it is a Pronic number which means number = n(n + 1).

In this Python program, the i value iterates from zero to the square root of that number and checks whether the product of any two consecutive numbers equals the actual number. If True, the flag value becomes one, and the break statement will exit from the loop. If the flag equals one, it is a Pronic number.

import math

Number = int(input("Enter the Number to Check Pronic Number = "))

i = 0
flag = 0

while i <= (int) (math.sqrt(Number)):
    if Number == i * (i + 1):
        flag = 1
        break
    i = i + 1

if flag == 1:
    print("\n%d is a Pronic Number." %Number)
else:
    print("%d is Not a Pronic Number." %Number)
Python Program to Check a Number is a Pronic Number

Python program to check whether a given number is a Pronic number or not using the for loop. 

Number = int(input("Enter the Number to Check Pronic Number = "))

flag = 0

for i in range(Number + 1):
    if Number == i * (i + 1):
        flag = 1
        break

if flag == 1:
    print("\n%d is a Pronic Number." %Number)
else:
    print("%d is Not a Pronic Number." %Number)
Enter the Number to Check Pronic Number = 42

42 is a Pronic Number.

Enter the Number to Check Pronic Number = 55
55 is Not a Pronic Number.

Python program to find a number is a Pronic number or not using functions.

def pronicNumber(Number):
    flag = 0
    for i in range(Number + 1):
        if Number == i * (i + 1):
            flag = 1
            break
    return flag
        
Number = int(input("Enter the Number to Check Pronic Number = "))

if pronicNumber(Number) == 1:
    print("\n%d is a Pronic Number." %Number)
else:
    print("%d is Not a Pronic Number." %Number)
Enter the Number to Check Pronic Number = 52
52 is Not a Pronic Number.

Enter the Number to Check Pronic Number = 72

72 is a Pronic Number.