Program to Check Pronic Number or Not

Python Program to Check Pronic Number or Not

In the previous article, we have discussed Python Program to Calculate the Discriminant Value
Pronic Number:

A pronic number is the product of two consecutive integers, i.e. a number of the form n(n + 1).

Pronic numbers are also referred to as oblong numbers or heteromecic numbers.

Pronic numbers include 0, 2, 6, 12, 20, 30, 42, 56, 72, 90, 110, 132, 156, 182, 210, 240, 272, 306, 342, 380, 420, and 462 etc.

Examples:

Example 1:

Input:

Given number = 240

Output: 

The given number{ 240 } is a pronic number

Example 2:

Input:

Given number = 15

Output: 

The given number{ 15 } is Not a pronic number

Program to Check Pronic Number or Not

Below are the ways to check the given number is a pronic number or not

Method #1: Using For Loop (Static Input)

Approach:

  • Give the number as static input and store it in a variable.
  • Take a variable say ‘count’ and initialize its value with ‘0’.
  • Loop from 0 to above-given number using for loop.
  • Inside the loop, check if the product of the iterator value and iterator+1 value (consecutive integers) is equal to the given number using the if conditional statement.
  • If the statement is true, then increment the value of count (i.e. 1), give the break condition, and come out of the loop.
  • Check if the value of count is equal to ‘1’ using the if conditional statement.
  • If the statement is true, then print “The given number is pronic number”.
  • Else print “The given number is Not a pronic number”.
  • The Exit of the program.

Below is the implementation:

# Give the number as static input and store it in a variable.
numb = 156
# Take a variable say 'count' and initialize its value with '0'.
count = 0
# Loop from 0 to above-given number using for loop. 
for itr in range(numb):
    # Inside the loop, check if the product of the iterator value and iterator+1 value
    # (consecutive integers) is equal to the given number using the if conditional statement.
    if itr * (itr + 1) == numb:
        # If the statement is true, then increment the value of count (i.e. 1),
        # give the break condition and come out of the loop.
        count = 1
        break
# Check if the value of count is equal to '1' using the if conditional statement.
if count == 1:
  # If the statement is true, then print "The given number is a pronic number".
    print("The given number{",numb,"} is a pronic number")
# Else print "The given number is Not a pronic number".
else:
    print("The given number{",numb,"} is Not a pronic number")

Output: 

The given number{ 156 } is a pronic number

Method #2: Using For Loop (User Input)

Approach:

  • Give the number as user input using the int(input()) function and store it in a variable.
  • Take a variable say ‘count’ and initialize its value with ‘0’.
  • Loop from 0 to above-given number using for loop.
  • Inside the loop, check if the product of the iterator value and iterator+1 value (consecutive integers) is equal to the given number using the if conditional statement.
  • If the statement is true, then increment the value of count (i.e. 1), give the break condition, and come out of the loop.
  • Check if the value of count is equal to ‘1’ using the if conditional statement.
  • If the statement is true, then print “The given number is pronic number”.
  • Else print “The given number is Not a pronic number”.
  • The Exit of the program.

Below is the implementation:

# Give the number as user input using int(input()) function and store it in a variable.
numb = int(input("Enter some random number = "))
# Take a variable say 'count' and initialize its value with '0'.
count = 0
# Loop from 0 to above-given number using for loop. 
for itr in range(numb):
    # Inside the loop, check if the product of the iterator value and iterator+1 value
    # (consecutive integers) is equal to the given number using the if conditional statement.
    if itr * (itr + 1) == numb:
        # If the statement is true, then increment the value of count (i.e. 1),
        # give the break condition and come out of the loop.
        count = 1
        break
# Check if the value of count is equal to '1' using the if conditional statement.
if count == 1:
  # If the statement is true, then print "The given number is a pronic number".
    print("The given number{",numb,"} is a pronic number")
# Else print "The given number is Not a pronic number".
else:
    print("The given number{",numb,"} is Not a pronic number")

Output: 

Enter some random number = 90
The given number{ 90 } is a pronic number

Explore more instances related to python concepts from Python Programming Examples Guide and get promoted from beginner to professional programmer level in Python Programming Language.