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 = "))

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 = 42

42 is a Pronic Number.

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

This Python program helps 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 = "))

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

Enter the Number to Check Pronic = 72

72 is a Pronic Number.