Python

Program to Print Series 6, 9, 14, 21, 30, 41, 54 ... N

Python Program to Print Series 6, 9, 14, 21, 30, 41, 54 … N

In the previous article, we have discussed Python Program to Print Series 1, -2, 6, -15, 31 … N
Given a number N and the task is to print the series (6, 9, 14, 21, 30, 41, 54 … N) till the given number N in Python.

Examples:

Example1:

Input:

Given Number (Limit) = 7

Output:

The above series till the given number{ 7 } is :
6 9 14 21 30 41 54

Example2:

Input:

Given Number (Limit) = 10

Output:

The above series till the given number{ 10 } is :
6 9 14 21 30 41 54 69 86 105

Program to Print Series 6, 9, 14, 21, 30, 41, 54 … N in Python

Below are the ways to print the series (6, 9, 14, 21, 30, 41, 54 … N) till the given number N in Python :

Method #1: Using While Loop (Static Input)

Approach:

  • Give the number N (Limit) as static input and store it in a variable.
  • Take a variable to say itr and initialize its value to 1.
  • Take another variable say k and initialize its value to 3.
  • Take another variable say valu and initialize its value to 6.
  • Loop until the above-declared variable itr value is less than or equal to the given number using the while loop.
  • Inside the loop, print the value of the above variable valu separated by spaces.
  • Add k value to the above valu and store it in the same variable valu.
  • Increment the above k value by 2.
  • Increment the above itr value by 1.
  • The Exit of the Program.

Below is the implementation:

# Give the number N (Limit) as static input and store it in a variable.
gvn_numb = 7
# Take a variable to say itr and initialize its value to 1.
itr = 1
# Take another variable say k and initialize its value to 3.
k = 3
# Take another variable say valu and initialize its value to 6.
valu = 6
print("The above series till the given number{", gvn_numb, "} is :")
# Loop until the above-declared variable itr value is less than or equal to the given
# number using the while loop.
while(itr <= gvn_numb):
    # Inside the loop, print the value of the above variable valu separated by spaces.
    print(valu, end=" ")
    # Add k value to the above valu and store it in the same variable valu.
    valu += k
    # Increment the above k value by 2.
    k += 2
    # Increment the above itr value by 1.
    itr += 1

Output:

The above series till the given number{ 7 } is :
6 9 14 21 30 41 54

Method #2: Using While loop (User Input)

Approach:

  • Give the number N (Limit) as user input using the int(input()) function and store it in a variable.
  • Take a variable to say itr and initialize its value to 1.
  • Let us Take another variable say k and initialize its value to 3.
  • Take another variable say valu and initialize its value to 6.
  • Loop until the above-declared variable itr value is less than or equal to the given number using the while loop.
  • Inside the loop, print the value of the above variable valu separated by spaces.
  • Add k value to the above valu and store it in the same variable valu.
  • Increment the above k value by 2.
  • Increment the above itr value by 1.
  • The Exit of the Program.

Below is the implementation:

# Give the number N (Limit) as user input using the int(input()) function and 
# store it in a variable.
gvn_numb = int(input("Enter some Random Number = "))
# Take a variable to say itr and initialize its value to 1.
itr = 1
# Take another variable say k and initialize its value to 3.
k = 3
# Take another variable say valu and initialize its value to 6.
valu = 6
print("The above series till the given number{", gvn_numb, "} is :")
# Loop until the above-declared variable itr value is less than or equal to the given
# number using the while loop.
while(itr <= gvn_numb):
    # Inside the loop, print the value of the above variable valu separated by spaces.
    print(valu, end=" ")
    # Add k value to the above valu and store it in the same variable valu.
    valu += k
    # Increment the above k value by 2.
    k += 2
    # Increment the above itr value by 1.
    itr += 1

Output:

Enter some Random Number = 10
The above series till the given number{ 10 } is :
6 9 14 21 30 41 54 69 86 105

Enhance your coding skills with our list of Python Basic Programs provided and become a pro in the general-purpose programming language Python in no time.

Python Program to Print Series 6, 9, 14, 21, 30, 41, 54 … N Read More »

Program to Find Sum of Series 1^11!+2^22!+3^33!...+n^nn!

Python Program to Find Sum of Series 1^1/1!+2^2/2!+3^3/3!…+n^n/n!

In the previous article, we have discussed Python Program to Find Sum of Series 1^1/1+2^2/2+3^3/3…+n^n/n
Given a number N and the task is to find the sum of series (1^1/1!+2^2/2!+3^3/3!…+N^N/N!) till the given number N in Python.

Examples:

Example1:

Input:

Given Number (Limit) = 6

Output:

The above series sum till the given number N{ 6 } =  109.00833333333333

Example2:

Input:

Given Number (Limit) = 15

Output:

The above series sum till the given number N{ 15 } =  541239.9325756768

Program to Find Sum of Series 1^1/1!+2^2/2!+3^3/3!…+n^n/n! in Python

Below are the ways to find the sum of series (1^1/1!+2^2/2!+3^3/3!…+N^N/N!) till the given number N in Python:

Method #1: Using For Loop (Static Input)

Approach:

  • Import math module using the import keyword.
  • Give the number N (Limit) as static input and store it in a variable.
  • Take a variable to say rsltseries_summ and initialize its value to 0.0 (Floating point number).
  • Take another variable to say factl_rslt and initialize its value to 1
  • Loop from 1 to the given number using the for loop.
  • Inside the loop, multiply the iterator value with the above factl_rslt and store it in the same variable.
  • Calculate the value of the iterator raised to the power itself and divided by the above factorial result using the pow() function.
  • Store it in another variable.
  • Add the above result to the rsltseries_summ and store it in the same variable.
  • Print the sum of series till the given number N.
  • The Exit of the Program.

Below is the implementation:

# Import math module using the import keyword.
import math
# Give the number N(limit) as static input and store it in a variable.
gvn_numb = 6
# Take a variable to say rsltseries_summ and initialize its value to 0.0
# (Floating point number)
rsltseries_summ = 0.0
# Take another variable to say factl_rslt and initialize its value to 1
factl_rslt = 1
# Loop from 1 to the given number using the for loop.
for itr in range(1, gvn_numb+1):
    # Inside the loop, multiply the iterator value with the above factl_rslt and
    # store it in the same variable.
    factl_rslt *= itr
    # calculate the value of the iterator raised to the power itself and
    # divided by the above factorial result using the pow() function.
    # Store it in another variable.
    a = pow(itr, itr) / factl_rslt
    # Add the above result to the rsltseries_summ and store it in the same variable.
    rsltseries_summ += a
# Print the sum of series till the given number N.
print(
    "The above series sum till the given number N{", gvn_numb, "} = ", rsltseries_summ)

Output:

The above series sum till the given number N{ 6 } =  109.00833333333333

Method #2: Using For loop (User Input)

Approach:

  • Import math module using the import keyword.
  • Give the number N (Limit) as user input using the int(input()) function and store it in a variable.
  • Take a variable to say rsltseries_summ and initialize its value to 0.0 (Floating point number).
  • Take another variable to say factl_rslt and initialize its value to 1
  • Loop from 1 to the given number using the for loop.
  • Inside the loop, multiply the iterator value with the above factl_rslt and store it in the same variable.
  • Calculate the value of the iterator raised to the power itself and divided by the above factorial result using the pow() function.
  • Store it in another variable.
  • Add the above result to the rsltseries_summ and store it in the same variable.
  • Print the sum of series till the given number N.
  • The Exit of the Program.

Below is the implementation:

# Import math module using the import keyword.
import math
# Give the number N (Limit) as user input using the int(input()) function and 
# store it in a variable.
gvn_numb = int(input("Enter some Random Number = "))
# Take a variable to say rsltseries_summ and initialize its value to 0.0
# (Floating point number)
rsltseries_summ = 0.0
# Take another variable to say factl_rslt and initialize its value to 1
factl_rslt = 1
# Loop from 1 to the given number using the for loop.
for itr in range(1, gvn_numb+1):
    # Inside the loop, multiply the iterator value with the above factl_rslt and
    # store it in the same variable.
    factl_rslt *= itr
    # calculate the value of the iterator raised to the power itself and
    # divided by the above factorial result using the pow() function.
    # Store it in another variable.
    a = pow(itr, itr) / factl_rslt
    # Add the above result to the rsltseries_summ and store it in the same variable.
    rsltseries_summ += a
# Print the sum of series till the given number N.
print(
    "The above series sum till the given number N{", gvn_numb, "} = ", rsltseries_summ)

Output:

Enter some Random Number = 15
The above series sum till the given number N{ 15 } = 541239.9325756768

Remediate your knowledge gap by attempting the Python Code Examples regularly and understand the areas of need and work on them.

Python Program to Find Sum of Series 1^1/1!+2^2/2!+3^3/3!…+n^n/n! Read More »

Program to Check if Three Points are Collinear

Python Program to Check if Three Points are Collinear

In the previous article, we have discussed Python Program to Find Sum of Series 1^1/1!+2^2/2!+3^3/3!…+n^n/n!
Given three points the task is to check whether the given three points are collinear or not in Python.

Collinear Points:

Collinear points are those that are located along the same straight line or in a single line. In Euclidean geometry, two or more points on a line that is close to or far from each other are said to be collinear.

Examples:

Example1:

Input:

Given First Point = ( 1 , 1 )
Given Second Point = ( 1 , 4 )
Given Third Point = ( 1, 5 )

Output:

The points ( 1 , 1 ) ( 1 , 4 ) ( 1 , 5 ) are collinear and lies on the straight line

Example2:

Input:

Given First Point = ( 7 , 0 )
Given Second Point = ( 8, 9 )
Given Third Point = ( 1, 2 )

Output:

The points ( 7 , 0 ) ( 8 , 9 ) ( 1 , 2 ) are not collinear

Program to Check if Three Points are Collinear in Python

Below are the ways to check whether the given three points are collinear or not in Python:

Method #1: Using Mathematical Formula (Static Input)

Approach:

  • Give the first point as static input and store it in two variables.
  • Give the second point as static input and store it in another two variables.
  • Give the third point as static input and store it in another two variables.
  • Calculate the area of these three points and store it in a variable.
  • Check the above-calculated area is equal to 0 or not using the If conditional statement.
  • If it is true then the given three points are collinear and lie in the straight line.
  • Else the given three points are not collinear.
  • The Exit of the Program.

Below is the implementation:

# Give the first point as static input and store it in two variables.
a1 = 1
b1 = 1
# Give the second point as static input and store it in another two variables.
a2 = 1
b2 = 4
# Give the third point as static input and store it in another two variables.
a3 = 1
b3 = 5
# Calculate the area of these three points(triangle) and store it in a variable.
# To avoid floating point computations, we avoided multiplication with 0.5.
areaofPts = a1 * (b2 - b3) + a2 * (b3 - b1) + a3 * (b1 - b2)
# Check the above-calculated area is equal to 0 or not using the If conditional statement.
if(areaofPts == 0):
    # If it is true then the given three points are collinear and lie in the straight line.
    print('The points (', a1, ',', b1, ') (', a2, ',', b2, ') (', a3,
          ',', b3, ')', 'are collinear and lies on the straight line ')
else:
    # Else the given three points are not collinear.
    print('The points (', a1, ',', b1, ') (', a2, ',', b2, ') (', a3,
          ',', b3, ')', 'are not collinear ')

Output:

The points ( 1 , 1 ) ( 1 , 4 ) ( 1 , 5 ) are collinear and lies on the straight line

Method #2: Using Mathematical Formula (User Input)

Approach:

  • Give the first point as user input using map(),int(),split() functions and store it in two variables.
  • Give the second point as user input using map(),int(),split() functions and store it in two variables.
  • Give the third point as user input using map(),int(),split() functions and store it in two variables.
  • Calculate the area of these three points and store it in a variable.
  • Check the above-calculated area is equal to 0 or not using the If conditional statement.
  • If it is true then the given three points are collinear and lie in the straight line.
  • Else the given three points are not collinear.
  • The Exit of the Program.

Below is the implementation:

# Give the first point as user input using map(),int(),split() functions
# and store it in two variables.
a1, b1 = map(int, input(
    'Enter some random first point values separated by spaces = ').split())
# Give the second point as user input using map(),int(),split() functions
# and store it in two variables.
a2, b2 = map(int, input(
    'Enter some random second point values separated by spaces = ').split())
# Give the third point as user input using map(),int(),split() functions
# and store it in two variables.
a3, b3 = map(int, input(
    'Enter some random third point values separated by spaces = ').split())
# Calculate the area of these three points(triangle) and store it in a variable.
# To avoid floating point computations, we avoided multiplication with 0.5.
areaofPts = a1 * (b2 - b3) + a2 * (b3 - b1) + a3 * (b1 - b2)
# Check the above-calculated area is equal to 0 or not using the If conditional statement.
if(areaofPts == 0):
    # If it is true then the given three points are collinear and lie in the straight line.
    print('The points (', a1, ',', b1, ') (', a2, ',', b2, ') (', a3,
          ',', b3, ')', 'are collinear and lies on the straight line ')
else:
    # Else the given three points are not collinear.
    print('The points (', a1, ',', b1, ') (', a2, ',', b2, ') (', a3,
          ',', b3, ')', 'are not collinear ')

Output:

Enter some random first point values separated by spaces = 7 0
Enter some random second point values separated by spaces = 8 9
Enter some random third point values separated by spaces = 1 2
The points ( 7 , 0 ) ( 8 , 9 ) ( 1 , 2 ) are not collinear

If you are new to the Python Programming Language then practice using our Python Programming Examples for Beginners as our expert team has designed them from scratch.

Python Program to Check if Three Points are Collinear Read More »

Program to Find N’th Pentagonal Number

Python Program to Find N’th Pentagonal Number

In the previous article, we have discussed Python Program to Check if Three Points are Collinear
Given a number N the task is to find the Nth Pentagonal Number in Python.

Nth Pentagonal Number:

n is the nth pentagonal number. When the pentagons are overlapped so that they share one vertex, Pn is the number of different dots in a pattern of dots consisting of the outlines of regular pentagons with sides up to n dots.

A polygonal number (triangular number, square number, and so on) is a number that is represented as dots or pebbles ordered in the shape of a regular polygon. The first few pentagonal numbers are as follows: 1, 5, 12, and so on.

Examples:

Example1:

Input:

Given Number = 4

Output:

The { 4 } pentagonal number =  22

Example2:

Input:

Given Number = 6

Output:

The { 6 } pentagonal number = 51

Program to Find N’th Pentagonal Number in Python

Below are the ways to find the Nth Pentagonal Number in Python:

Nth Pentagonal Number Formula = 3*n*(n-1)/2 + n     (or)  (3*n*n – n)/2

Method #1: Using Mathematical Formula (Static Input)

Approach:

  • Give the number N as static Input and store it in a variable.
  • Create a function nthPentagonalNumb() which accepts the given number as an argument and returns the nth pentagonal number.
  • Inside the nthPentagonalNumb() function.
  • Calculate the value of (3*n*n – n)/2 where n is the argument and store it in a variable say reslt.
  • Return the reslt.
  • Pass the given Number as an argument to nthPentagonalNumb() function and store the result returned from the function in a variable say nthNumb.
  • Print the nthNumb value.
  • The Exit of the Program.

Below is the implementation:

# Create a function nthPentagonalNumb() which accepts the given number
# as an argument and returns the nth pentagonal number.


def nthPentagonalNumb(numb):
        # Inside the nthPentagonalNumb() function.
        # Calculate the value of (3*n*n - n)/2 where n is the argument and
    # store it in a variable say reslt.
    reslt = (3*numb*numb - numb)/2
    # Return the reslt.
    return int(reslt)


# Give the number N as static Input and store it in a variable.
gvnnumb = 4
# Pass the given Number as an argument to nthPentagonalNumb() 
# function and store the result returned from the function in a variable say nthNumb.
nthNumb = nthPentagonalNumb(gvnnumb)
# Print the nthNumb value.
print('The {', gvnnumb, '} pentagonal number = ', nthNumb)

Output:

The { 4 } pentagonal number =  22

Method #2: Using Mathematical Formula (User Input)

Approach:

  • Give the number N as user Input using the int(input()) function and store it in a variable.
  • Create a function nthPentagonalNumb() which accepts the given number as an argument and returns the nth pentagonal number.
  • Inside the nthPentagonalNumb() function.
  • Calculate the value of (3*n*n – n)/2 where n is the argument and store it in a variable say reslt.
  • Return the reslt.
  • Pass the given Number as an argument to nthPentagonalNumb() function and store the result returned from the function in a variable say nthNumb.
  • Print the nthNumb value.
  • The Exit of the Program.

Below is the implementation:

# Create a function nthPentagonalNumb() which accepts the given number
# as an argument and returns the nth pentagonal number.


def nthPentagonalNumb(numb):
        # Inside the nthPentagonalNumb() function.
        # Calculate the value of (3*n*n - n)/2 where n is the argument and
    # store it in a variable say reslt.
    reslt = (3*numb*numb - numb)/2
    # Return the reslt.
    return int(reslt)


# Give the number N as user Input using the int(input()) function
# and store it in a variable.
gvnnumb = int(input('Enter some random Number = '))
# Pass the given Number as an argument to nthPentagonalNumb() 
# function and store the result returned from the function in a variable say nthNumb.
nthNumb = nthPentagonalNumb(gvnnumb)
# Print the nthNumb value.
print('The {', gvnnumb, '} pentagonal number = ', nthNumb)

Output:

Enter some random Number = 6
The { 6 } pentagonal number = 51

Dive into numerous Python Programming Language Examples for practice and get the best out of the tutorial and learn python one step at a time.

Python Program to Find N’th Pentagonal Number Read More »

Program to Find Sum of Series 1^11+2^22+3^33...+n^nn

Python Program to Find Sum of Series 1^1/1+2^2/2+3^3/3…+n^n/n

In the previous article, we have discussed Python Program to Find Sum of Series 1/2!+2/3!+3/5!+…..N/(N+1)!
Given a number N and the task is to find the sum of series (1^1/1+2^2/2+3^3/3…+N^N/N) till the given number N in Python.

Examples:

Example1:

Input:

Given Number (Limit) = 4

Output:

The above series sum till the given number N{ 4 } =  76.0

Example2:

Input:

Given Number (Limit) = 9

Output:

The above series sum till the given number N{ 9 } =  45269999.0

Program to Find Sum of Series 1^1/1+2^2/2+3^3/3…+n^n/n in Python

Below are the ways to find the sum of series (1^1/1+2^2/2+3^3/3…+N^N/N) till the given number N in Python:

Method #1: Using For Loop (Static Input)

Approach:

  • Import math module using the import keyword.
  • Give the number N (Limit) as static input and store it in a variable.
  • Take a variable to say rsltseries_summ and initialize its value to 0.0 (Floating point number).
  • Loop from 1 to the given number using the for loop.
  • Inside the loop, calculate the value of the iterator raised to the power itself and divided by the iterator value using the pow() function.
  • Store it in another variable.
  • Add the above result to the rsltseries_summ and store it in the same variable.
  • Print the sum of series till the given number N.
  • The Exit of the Program.

Below is the implementation:

# Import math module using the import keyword.
import math
# Give the number N(limit) as static input and store it in a variable.
gvn_numb = 4
# Take a variable to say rsltseries_summ and initialize its value to 0.0
# (Floating point number)
rsltseries_summ = 0.0
# Loop from 1 to the given number using the for loop.
for itr in range(1, gvn_numb+1):
        # Inside the loop, calculate the value of the iterator raised to the power itself and
        # divided by the iterator value using the pow() function.
        # Store it in another variable.
    a = pow(itr, itr) / itr
    # Add the above result to the rsltseries_summ and store it in the same variable.
    rsltseries_summ += a
# Print the sum of series till the given number N.
print(
    "The above series sum till the given number N{", gvn_numb, "} = ", rsltseries_summ)

Output:

The above series sum till the given number N{ 4 } =  76.0

Method #2: Using For loop (User Input)

Approach:

  • Import math module using the import keyword.
  • Give the number N (Limit) as user input using the int(input()) function and store it in a variable.
  • Take a variable to say rsltseries_summ and initialize its value to 0.0 (Floating point number).
  • Loop from 1 to the given number using the for loop.
  • Inside the loop, calculate the value of the iterator raised to the power itself and divided by the iterator value using the pow() function.
  • Store it in another variable.
  • Add the above result to the rsltseries_summ and store it in the same variable.
  • Print the sum of series till the given number N.
  • The Exit of the Program.

Below is the implementation:

# Import math module using the import keyword.
import math
# Give the number N (Limit) as user input using the int(input()) function and 
# store it in a variable.
gvn_numb = int(input("Enter some Random Number = "))
# Take a variable to say rsltseries_summ and initialize its value to 0.0
# (Floating point number)
rsltseries_summ = 0.0
# Loop from 1 to the given number using the for loop.
for itr in range(1, gvn_numb+1):
    # Inside the loop, calculate the value of the iterator raised to the power itself and
    # divided by the iterator value using the pow() function.
    # Store it in another variable.
    a = pow(itr, itr) / itr
    # Add the above result to the rsltseries_summ and store it in the same variable.
    rsltseries_summ += a
# Print the sum of series till the given number N.
print(
    "The above series sum till the given number N{", gvn_numb, "} = ", rsltseries_summ)

Output:

Enter some Random Number = 9
The above series sum till the given number N{ 9 } = 45269999.0

Explore more Example Python Programs with output and explanation and practice them for your interviews, assignments and stand out from the rest of the crowd.

Python Program to Find Sum of Series 1^1/1+2^2/2+3^3/3…+n^n/n Read More »

Program to Find Sum of Series 5^2+10^2+15^2+.....N^2

Python Program to Find Sum of Series 5^2 + 10^2 + 15^2 +…..N^2

In the previous article, we have discussed Python Program to Print Series 0 2 6 12 20 30 42…N
Given a number N and the task is to find the sum of series (5^2+10^2+15^2+…..N^2) till the given number N in Python.

Examples:

Example1:

Input:

Given Number (Limit) = 25

Output:

The above given series sum =  1375

Example2:

Input:

Given Number (Limit) = 14

Output:

The above given series sum =  125

Program to Find Sum of Series 5^2+10^2+15^2+…..N^2 in Python

Below are the ways to find the sum of series (5^2+10^2+15^2+…..N^2) till the given number N in Python:

Method #1: Using While Loop (Static Input)

Approach:

  • Import math module using the import keyword.
  • Give the number N (Limit) as static input and store it in a variable.
  • Take a variable to say itr and initialize its value to 5.
  • Take another variable to say rsltseries_summ and initialize its value to 0.
  • Loop until the above-declared variable itr value is less than or equal to the given number using the while loop.
  • Calculate the value of itr raised to the power 2 (square) using the pow() function and store it in another variable.
  • Add the above result to the rsltseries_summ and store it in the same variable.
  • Increment the above itr value by 5.
  • Print the sum of series till the given number N.
  • The Exit of the Program.

Below is the implementation:

# Import math module using the import keyword.
import math
# Give the number N(limit) as static input and store it in a variable.
gvn_numb = 25
# Take a variable to say itr and initialize its value to 5.
itr = 5
# Take a variable to say rsltseries_summ and initialize its value to 0.
rsltseries_summ = 0
# Loop until the above-declared variable itr value is less than or equal to the
# given number using the while loop.
while(itr <= gvn_numb):
    # Calculate the value of itr raised to the power 2 (square) using the pow() function
    # and store it in another variable.
    k = pow(itr, 2)
    # Add the above result to the rsltseries_summ and store it in the
    # same variable.
    rsltseries_summ += k
    # Increment the above itr value by 5.
    itr += 5
print("The above given series sum = ", rsltseries_summ)

Output:

The above given series sum =  1375

Method #2: Using While loop (User Input)

Approach:

  • Import math module using the import keyword.
  • Give the number N (Limit) as user input using the int(input()) function and store it in a variable.
  • Take a variable to say itr and initialize its value to 5.
  • Take another variable to say rsltseries_summ and initialize its value to 0.
  • Loop until the above-declared variable itr value is less than or equal to the given number using the while loop.
  • Calculate the value of itr raised to the power 2 (square) using the pow() function and store it in another variable.
  • Add the above result to the rsltseries_summ and store it in the same variable.
  • Increment the above itr value by 5.
  • Print the sum of series till the given number N.
  • The Exit of the Program.

Below is the implementation:

# Import math module using the import keyword.
import math
# Give the number N (Limit) as user input using the int(input()) function and 
# store it in a variable.
gvn_numb = int(input("Enter some Random Number = "))
# Take a variable to say itr and initialize its value to 5.
itr = 5
# Take a variable to say rsltseries_summ and initialize its value to 0.
rsltseries_summ = 0
# Loop until the above-declared variable itr value is less than or equal to the
# given number using the while loop.
while(itr <= gvn_numb):
    # Calculate the value of itr raised to the power 2 (square) using the pow() function
    # and store it in another variable.
    k = pow(itr, 2)
    # Add the above result to the rsltseries_summ and store it in the
    # same variable.
    rsltseries_summ += k
    # Increment the above itr value by 5.
    itr += 5
print("The above given series sum = ", rsltseries_summ)

Output:

Enter some Random Number = 14
The above given series sum = 125

Grab the opportunity and utilize the Python Program Code Examples over here to prepare basic and advanced topics too with ease and clear all your doubts.

Python Program to Find Sum of Series 5^2 + 10^2 + 15^2 +…..N^2 Read More »

Program to Print Series 0 2 6 12 20 30 42...N

Python Program to Print Series 0 2 6 12 20 30 42…N

In the previous article, we have discussed Python Program to Print Series 1 2 5 8 15 28 51 94….N
Given a number N and the task is to print the series (0 2 6 12 20 30 42…N) till the given number N in Python.

Examples:

Example1:

Input:

Given Number (Limit) = 9

Output:

The above series till the given number{ 9 } is :
0 2 6 12 20 30 42 56 72

Example2:

Input:

Given Number (Limit) = 10

Output:

The above series till the given number{ 10 } is :
0 2 6 12 20 30 42 56 72 90

Program to Print Series 0 2 6 12 20 30 42…N in Python

Below are the ways to print the series (0 2 6 12 20 30 42…N) till the given number N in python:

Method #1: Using While Loop (Static Input)

Approach:

  • Give the number N (Limit) as static input and store it in a variable.
  • Take a variable to say itr and initialize its value to 1.
  • Loop until the above-declared variable itr value is less than or equal to the given number using the while loop.
  • Multiply the above itr value with itself and subtract again the itr value from it.
  • Store it in another variable.
  • Print the value of the above result separated by spaces using the end function.
  • Increment the above itr value by 1.
  • The Exit of the Program.

Below is the implementation:

# Give the number N(limit) as static input and store it in a variable.
gvn_numb = 9
# Take a variable to say itr and initialize its value to 1.
itr = 1
print("The above series till the given number{", gvn_numb, "} is :")
# Loop until the above-declared variable itr value is less than or equal to the
# given number using the while loop.
while itr <= gvn_numb:
    # Multiply the above itr value with itself and subtract again the itr value from it.
    # Store it in another variable.
    k = (itr*itr)-itr
    # Print the value of the above result separated by spaces using the end function.
    print(k, end=" ")
    # Increment the above itr value by 1.
    itr += 1

Output:

The above series till the given number{ 9 } is :
0 2 6 12 20 30 42 56 72

Method #2: Using While loop (User Input)

Approach:

  • Give the number N (Limit) as user input using the int(input()) function and store it in a variable.
  • Take a variable to say itr and initialize its value to 1.
  • Loop until the above-declared variable itr value is less than or equal to the given number using the while loop.
  • Multiply the above itr value with itself and subtract again the itr value from it.
  • Store it in another variable.
  • Print the value of the above result separated by spaces using the end function.
  • Increment the above itr value by 1.
  • The Exit of the Program.

Below is the implementation:

# Give the number N (Limit) as user input using the int(input()) function and 
# store it in a variable.
gvn_numb = int(input("Enter some Random Number = "))
# Take a variable to say itr and initialize its value to 1.
itr = 1
print("The above series till the given number{", gvn_numb, "} is :")
# Loop until the above-declared variable itr value is less than or equal to the
# given number using the while loop.
while itr <= gvn_numb:
    # Multiply the above itr value with itself and subtract again the itr value from it.
    # Store it in another variable.
    k = (itr*itr)-itr
    # Print the value of the above result separated by spaces using the end function.
    print(k, end=" ")
    # Increment the above itr value by 1.
    itr += 1

Output:

Enter some Random Number = 10
The above series till the given number{ 10 } is :
0 2 6 12 20 30 42 56 72 90

Practice Python Program Examples to master coding skills and learn the fundamental concepts in the dynamic programming language Python.

Python Program to Print Series 0 2 6 12 20 30 42…N Read More »

Program to Print Series 1 2 5 8 15 28 51 94....N

Python Program to Print Series 1 2 5 8 15 28 51 94….N

In the previous article, we have discussed Python Program to Print Series 0, 6, 10, 17, 22, 30, 36…N
Given a number N and the task is to print the series (1 2 5 8 15 28 51 94….N) till the given number N in Python.

Examples:

Example1:

Input:

Given Number (Limit) = 13

Output:

The above series till the given number{ 13 } is :
1 2 5 8 15 28 51 94 173 318 585 1076 1979

Example2:

Input:

Given Number (Limit) = 8

Output:

The above series till the given number{ 8 } is :
1 2 5 8 15 28 51 94

Program to Print Series 1 2 5 8 15 28 51 94….N in Python

Below are the ways to print the series (1 2 5 8 15 28 51 94….N) till the given number N in Python:

Method #1: Using While Loop (Static Input)

Approach:

  • Give the number N (Limit) as static input and store it in a variable.
  • Take a variable to say itr and initialize its value to 4.
  • Check if the given number is greater than or equal to 1 using the if conditional statement.
  • If it is true, then print 1 separated by spaces using the end function.
  • Check if the given number is greater than or equal to 2 using the if conditional statement.
  • If it is true, then print 2 separated by spaces using the end function.
  • Check if the given number is greater than or equal to 3 using the if conditional statement.
  • If it is true, then print 5 separated by spaces using the end function.
  • Take another variable say m and initialize its value to 1.
  • Take another variable say n and initialize its value to 2.
  • Take another variable say o and initialize its value to 5.
  • Loop until the above-declared variable itr value is less than or equal to the given number using the while loop.
  • Inside the loop, add the above 3 values m, n, o and store them in a variable say rslt.
  • Assign the value of n to m.
  • Assign the value of o to n.
  • Assign the value of rslt to o.
  • Print the value of the rslt separated by spaces using the end function.
  • Increment the above itr value by 1.
  • The Exit of the Program.

Below is the implementation:

# Give the number N(limit) as static input and store it in a variable.
gvn_numb = 13
# Take a variable to say itr and initialize its value to 4.
itr = 4
print("The above series till the given number{", gvn_numb, "} is :")
# Check if the given number is greater than or equal to 1 using the if conditional
# statement.
if gvn_numb >= 1:
    # If it is true, then print 1 separated by spaces using the end function.
    print("1 ", end="")
# Check if the given number is greater than or equal to 2 using the if conditional
# statement.
if gvn_numb >= 2:
    # If it is true, then print 2 separated by spaces using the end function.
    print("2 ", end="")
# Check if the given number is greater than or equal to 3 using the if conditional
# statement.
if gvn_numb >= 3:
  # If it is true, then print 5 separated by spaces using the end function.
    print("5 ", end="")
# Take another variable say m and initialize its value to 1.
m = 1
# Take another variable say n and initialize its value to 2.
n = 2
# Take another variable say o and initialize its value to 5.
o = 5
# Loop until the above-declared variable itr value is less than or equal to the
# given number using the while loop.
while itr <= gvn_numb:
    # Inside the loop, add the above 3 values m, n, o and store them in a variable
    # say rslt.
    rslt = m + n + o
   # Assign the value of n to m.
    m = n
    # Assign the value of o to n.
    n = o
    # Assign the value of rslt to o.
    o = rslt
    # Print the value of the rslt separated by spaces using the end function.
    print(rslt, end=" ")
    # Increment the above itr value by 1.
    itr += 1

Output:

The above series till the given number{ 13 } is :
1 2 5 8 15 28 51 94 173 318 585 1076 1979

Method #2: Using While loop (User Input)

Approach:

  • Give the number N (Limit) as user input using the int(input()) function and store it in a variable.
  • Take a variable to say itr and initialize its value to 4.
  • Check if the given number is greater than or equal to 1 using the if conditional statement.
  • If it is true, then print 1 separated by spaces using the end function.
  • Check if the given number is greater than or equal to 2 using the if conditional statement.
  • If it is true, then print 2 separated by spaces using the end function.
  • Check if the given number is greater than or equal to 3 using the if conditional statement.
  • If it is true, then print 5 separated by spaces using the end function.
  • Take another variable say m and initialize its value to 1.
  • Take another variable say n and initialize its value to 2.
  • Take another variable say o and initialize its value to 5.
  • Loop until the above-declared variable itr value is less than or equal to the given number using the while loop.
  • Inside the loop, add the above 3 values m, n, o and store them in a variable say rslt.
  • Assign the value of n to m.
  • Assign the value of o to n.
  • Assign the value of rslt to o.
  • Print the value of the rslt separated by spaces using the end function.
  • Increment the above itr value by 1.
  • The Exit of the Program.

Below is the implementation:

# Give the number N (Limit) as user input using the int(input()) function and 
# store it in a variable.
gvn_numb = int(input("Enter some Random Number = "))
# Take a variable to say itr and initialize its value to 4.
itr = 4
print("The above series till the given number{", gvn_numb, "} is :")
# Check if the given number is greater than or equal to 1 using the if conditional
# statement.
if gvn_numb >= 1:
    # If it is true, then print 1 separated by spaces using the end function.
    print("1 ", end="")
# Check if the given number is greater than or equal to 2 using the if conditional
# statement.
if gvn_numb >= 2:
    # If it is true, then print 2 separated by spaces using the end function.
    print("2 ", end="")
# Check if the given number is greater than or equal to 3 using the if conditional
# statement.
if gvn_numb >= 3:
  # If it is true, then print 5 separated by spaces using the end function.
    print("5 ", end="")
# Take another variable say m and initialize its value to 1.
m = 1
# Take another variable say n and initialize its value to 2.
n = 2
# Take another variable say o and initialize its value to 5.
o = 5
# Loop until the above-declared variable itr value is less than or equal to the
# given number using the while loop.
while itr <= gvn_numb:
    # Inside the loop, add the above 3 values m, n, o and store them in a variable
    # say rslt.
    rslt = m + n + o
   # Assign the value of n to m.
    m = n
    # Assign the value of o to n.
    n = o
    # Assign the value of rslt to o.
    o = rslt
    # Print the value of the rslt separated by spaces using the end function.
    print(rslt, end=" ")
    # Increment the above itr value by 1.
    itr += 1


Output:

Enter some Random Number = 8
The above series till the given number{ 8 } is :
1 2 5 8 15 28 51 94

If you wanna write simple python programs as a part of your coding practice refer to numerous Simple Python Program Examples existing and learn the approach used.

Python Program to Print Series 1 2 5 8 15 28 51 94….N Read More »

Program to Print Series 0, 6, 10, 17, 22, 30, 36...N

Python Program to Print Series 0, 6, 10, 17, 22, 30, 36…N

In the previous article, we have discussed Python Program to Print Series 10, 5, 60, 15, 110 …N
Given a number N and the task is to print the series (0, 6, 10, 17, 22, 30, 36…N) till the given number N in Python.

Examples:

Example1:

Input:

Given Number (Limit) = 16

Output:

The above series till the given number{ 16 } is :
0 6 10 17 22 30 36 45 52 62 70 81 90 102 112 125

Example2:

Input:

Given Number (Limit) = 11

Output:

The above series till the given number{ 11 } is :
0 6 10 17 22 30 36 45 52 62 70

Program to Print Series 0, 6, 10, 17, 22, 30, 36…N in Python

Below are the ways to print the series (0, 6, 10, 17, 22, 30, 36…N) till the given number N in Python:

Method #1: Using While Loop (Static Input)

Approach:

  • Give the number N (Limit) as static input and store it in a variable.
  • Take a variable to say itr and initialize its value to 1.
  • Take another variable say m and initialize its value to 0.
  • Take another variable say n and initialize its value to 6.
  • Take another variable say x and initialize its value to 10.
  • Take another variable say y and initialize its value to 11.
  • Loop until the above-declared variable itr value is less than or equal to the given number using the while loop.
  • Inside the loop, check if the above variable itr value is even or not using the if conditional statement.
  • If it is true, then print the value of n separated by spaces.
  • Add the above y value to n and store it in the same variable n.
  • Increment the above y value by 2.
  • Else,  print the value of m separated by spaces.
  • Add the above x value to m and store it in the same variable m.
  • Increment the above x value by 2.
  • Increment the above itr value by 1.
  • The Exit of the Program.

Below is the implementation:

# Give the number N(limit) as static input and store it in a variable.
gvn_numb = 16
# Take a variable to say itr and initialize its value to 1.
itr = 1
# Take another variable say m and initialize its value to 0.
m = 0
# Take another variable say n and initialize its value to 6.
n = 6
# Take another variable say x and initialize its value to 10.
x = 10
# Take another variable say y and initialize its value to 11.
y = 11
print("The above series till the given number{", gvn_numb, "} is :")
# Loop until the above-declared variable itr value is less than or equal to the
# given number using the while loop.
while(itr <= gvn_numb):
        # Inside the loop, check if the above variable itr value is even or not using the
    # if conditional statement.
    if (itr % 2 == 0):
        # If it is true, then print the value of n separated by spaces.
        print(n, end=" ")
        # Add the above y value to n and store it in the same variable n.
        n += y
        # Increment the above y value by 2.
        y += 2
    else:
        # Else, print the value of m separated by spaces.
        print(m, end=" ")
        # Add the above x value to m and store it in the same variable m.
        m += x
        # Increment the above x value by 2.
        x += 2
   # Increment the above itr value by 1.
    itr += 1

Output:

The above series till the given number{ 16 } is :
0 6 10 17 22 30 36 45 52 62 70 81 90 102 112 125

Method #2: Using While loop (User Input)

Approach:

  • Give the number N (Limit) as user input using the int(input()) function and store it in a variable.
  • Take a variable to say itr and initialize its value to 1.
  • Take another variable say m and initialize its value to 0.
  • Take another variable say n and initialize its value to 6.
  • Take another variable say x and initialize its value to 10.
  • Take another variable say y and initialize its value to 11.
  • Loop until the above-declared variable itr value is less than or equal to the given number using the while loop.
  • Inside the loop, check if the above variable itr value is even or not using the if conditional statement.
  • If it is true, then print the value of n separated by spaces.
  • Add the above y value to n and store it in the same variable n.
  • Increment the above y value by 2.
  • Else,  print the value of m separated by spaces.
  • Add the above x value to m and store it in the same variable m.
  • Increment the above x value by 2.
  • Increment the above itr value by 1.
  • The Exit of the Program.

Below is the implementation:

# Give the number N (Limit) as user input using the int(input()) function and 
# store it in a variable.
gvn_numb = int(input("Enter some Random Number = "))
# Take a variable to say itr and initialize its value to 1.
itr = 1
# Take another variable say m and initialize its value to 0.
m = 0
# Take another variable say n and initialize its value to 6.
n = 6
# Take another variable say x and initialize its value to 10.
x = 10
# Take another variable say y and initialize its value to 11.
y = 11
print("The above series till the given number{", gvn_numb, "} is :")
# Loop until the above-declared variable itr value is less than or equal to the
# given number using the while loop.
while(itr <= gvn_numb):
        # Inside the loop, check if the above variable itr value is even or not using the
    # if conditional statement.
    if (itr % 2 == 0):
        # If it is true, then print the value of n separated by spaces.
        print(n, end=" ")
        # Add the above y value to n and store it in the same variable n.
        n += y
        # Increment the above y value by 2.
        y += 2
    else:
        # Else, print the value of m separated by spaces.
        print(m, end=" ")
        # Add the above x value to m and store it in the same variable m.
        m += x
        # Increment the above x value by 2.
        x += 2
   # Increment the above itr value by 1.
    itr += 1

Output:

Enter some Random Number = 11
The above series till the given number{ 11 } is :
0 6 10 17 22 30 36 45 52 62 70

 

Python Program to Print Series 0, 6, 10, 17, 22, 30, 36…N Read More »

Program to Print Series 10, 5, 60, 15, 110 ...N

Python Program to Print Series 10, 5, 60, 15, 110 …N

In the previous article, we have discussed Python Program to Print Series -1 4 -7 10 -13 16 -19…n
Given a number N and the task is to print the series ( 10, 5, 60, 15, 110 …N) till the given number N in Python.

Examples:

Example1:

Input:

Given Number (Limit) = 14

Output:

The above series till the given number{ 14 } is :
10 5 60 15 110 25 160 35 210 45 260 55 310 65

Example2:

Input:

Given Number (Limit) = 9

Output:

The above series till the given number{ 9 } is :
10 5 60 15 110 25 160 35 210

Program to Print Series 10, 5, 60, 15, 110 …N in Python

Below are the ways to print the series ( 10, 5, 60, 15, 110 …N) till the given number N in Python:

Method #1: Using While Loop (Static Input)

Approach:

  • Give the number N (Limit) as static input and store it in a variable.
  • Take a variable to say itr and initialize its value to 1.
  • Take another variable say p and initialize its value to 10.
  • Take another variable say q and initialize its value to 5.
  • Loop until the above-declared variable itr value is less than or equal to the given number using the while loop.
  • Inside the loop, check if the above variable itr value is even or not using the if conditional statement.
  • If it is true, then print the value of q separated by spaces.
  • Increment the above q value by 10 and store it in the same variable.
  • Else, print the value of p separated by spaces.
  • Increment the above p value by 50 and store it in the same variable.
  • Increment the above itr value by 1.
  • The Exit of the Program.

Below is the implementation:

# Give the number N(limit) as static input and store it in a variable.
gvn_numb = 14
# Take a variable to say itr and initialize its value to 1.
itr = 1
# Take another variable say p and initialize its value to 10.
p = 10
# Take another variable say q and initialize its value to 5.
q = 5
print("The above series till the given number{", gvn_numb, "} is :")
# Loop until the above-declared variable itr value is less than or equal to the
# given number using the while loop.
while(itr <= gvn_numb):
    # Inside the loop, check if the above variable itr value is even or not using the
    # if conditional statement.
    if(itr % 2 == 0):
        # If it is true, then print the value of q separated by spaces.
        print(q, end=" ")
        # Increment the above q value by 10 and store it in the same variable.
        q += 10
    else:
        # Else, print the value of p separated by spaces.
        print(p, end=" ")
        # Increment the above p value by 50 and store it in the same variable.
        p += 50
    # Increment the above itr value by 1.
    itr += 1

Output:

The above series till the given number{ 14 } is :
10 5 60 15 110 25 160 35 210 45 260 55 310 65

Method #2: Using While loop (User Input)

Approach:

  • Give the number N (Limit) as user input using the int(input()) function and store it in a variable.
  • Take a variable to say itr and initialize its value to 1.
  • Take another variable say p and initialize its value to 10.
  • Take another variable say q and initialize its value to 5.
  • Loop until the above-declared variable itr value is less than or equal to the given number using the while loop.
  • Inside the loop, check if the above variable itr value is even or not using the if conditional statement.
  • If it is true, then print the value of q separated by spaces.
  • Increment the above q value by 10 and store it in the same variable.
  • Else, print the value of p separated by spaces.
  • Increment the above p value by 50 and store it in the same variable.
  • Increment the above itr value by 1.
  • The Exit of the Program.

Below is the implementation:

# Give the number N (Limit) as user input using the int(input()) function and 
# store it in a variable.
gvn_numb = int(input("Enter some Random Number = "))
# Take a variable to say itr and initialize its value to 1.
itr = 1
# Take another variable say p and initialize its value to 10.
p = 10
# Take another variable say q and initialize its value to 5.
q = 5
print("The above series till the given number{", gvn_numb, "} is :")
# Loop until the above-declared variable itr value is less than or equal to the
# given number using the while loop.
while(itr <= gvn_numb):
    # Inside the loop, check if the above variable itr value is even or not using the
    # if conditional statement.
    if(itr % 2 == 0):
        # If it is true, then print the value of q separated by spaces.
        print(q, end=" ")
        # Increment the above q value by 10 and store it in the same variable.
        q += 10
    else:
        # Else, print the value of p separated by spaces.
        print(p, end=" ")
        # Increment the above p value by 50 and store it in the same variable.
        p += 50
    # Increment the above itr value by 1.
    itr += 1

Output:

Enter some Random Number = 9
The above series till the given number{ 9 } is :
10 5 60 15 110 25 160 35 210

Find the best practical and ready-to-use Python Programming Examples that you can simply run on a variety of platforms and never stop learning.

Python Program to Print Series 10, 5, 60, 15, 110 …N Read More »