Program to print all Pronic number between 1 to 100 in Python

Program to print all Pronic number between 1 to 100 in Python. The programs contains if else conditional statements, function definition, function calling and for loop. This program is for Beginners, class 11,12 and B Tech computer science students.

Print all Pronic number between 1 to 100 in Python.

What is A pronic number ?

A pronic number is a number that is the product of two consecutive integers, that is, a number of the form {\displaystyle n(n+1).}
For example:
6 = 2(2+1)= n(n+1),
72 =8(8+1) = n(n+1)
Some pronic numbers are: 0, 2, 6, 12, 20, 30, 42, 56 etc.

Source code :

    
def isPronicNumber(num):    
    flag = False;    
        
    for j in range(1, num+1):    
        #Checks for pronic number by multiplying consecutive numbers    
        if((j*(j+1)) == num):    
            flag = True;    
            break;    
    return flag;    
     
    
print("Pronic numbers between 1 and 100: ");    
for i in range(1, 101):    
    if(isPronicNumber(i)):    
        print(i),    
        print(" "),

Source code explanation:

step 1: isPronicNumber() will determine whether a given number is a pronic number or not
def isPronicNumber(num):
flag = False;
for j in range(1, num+1):
#Checks for pronic number by multiplying consecutive numbers
if((j*(j+1)) == num):
flag = True;
break;
return flag;
step 2: Displays pronic numbers between 1 and 100
print(“Pronic numbers between 1 and 100: “);
for i in range(1, 101):
if(isPronicNumber(i)):
print(i),
print(” “),

Output :

Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> 
 RESTART: C:/csstudy/source code file 2/Program to print all Pronic number between 1 to 100 in Python.py 
Pronic numbers between 1 and 100: 
2
 
6
 
12
 
20
 
30
 
42
 
56
 
72
 
90
 
>>> 

Output explanation:

Pronic numbers between 1 and 100: 2 6 12 20 30 42 56 72 90

Conclusion:

The program is running fine.

Thank you for reading, learning and downloading Program to print all Pronic number between 1 to 100 in Python. The programs contains if else conditional statements, function definition, function calling and for loop. This program is for Beginners, class 11,12 and B Tech computer science students. Below are more links to programs:
Python Programs Archives – CS Study
Computer Science with Python Practical Book Solutions Class 11 Term -2 – CS Study
Computer Science Practical file for class 12 Term-2 – CS Study
Python Projects for Class 12 with Source Code (Mysql Connectivity) – CS Study

Leave a Comment

Your email address will not be published.