Python

Program for Maximum Number of Squares that Can Fit in a Right Angle Isosceles Triangle

Python Program for Maximum Number of Squares that Can Fit in a Right Angle Isosceles Triangle

In the previous article, we have discussed Python Program for Minimum Height of a Triangle with Given Base and Area
Given the base b of an isosceles triangle and a value m, the task is to find the count of the maximum number of squares of side length m that can be fitted inside the given isosceles triangle.

Formula:

(b / m – 1) * (b / m) / 2

where b is the base of an isosceles triangle.

m is the sidelength of the square.

Examples:

Example1:

Input:

Given base of triangle = 8
Given side of square = 3

Output:

The maximum number of squares with given sidelength that can be fitted inside the isosceles triangle = 
2

Example2:

Input:

Given base of triangle = 5
Given side of square =  2

Output:

The maximum number of squares with given sidelength that can be fitted inside the isosceles triangle = 
1

Program for Maximum Number of Squares that Can Fit in a Right Angle Isosceles Triangle in Python

Below are the ways to find the count of the maximum number of squares of side length m that can be fitted inside the given isosceles triangle.

Method #1: Using Mathematical Formula (Static Input)

Approach:

  • Give the base of the triangle as static input and store it in a variable.
  • Give the side of the square as static input and store it in another variable.
  • Create a function to say count_maximumsqures() which takes the given base of the isosceles triangle and side of the square as the arguments and returns the count of the maximum number of squares of the given sidelength required that can be fitted inside the given isosceles triangle.
  • Inside the function, calculate the count of the maximum number of squares using the above mathematical formula and store it in a variable.
  • Return the above count value.
  • Pass the given base of the isosceles triangle and side of the square as the arguments to the count_maximumsqures() function, convert it into Integer using int() function, and print it.
  • The Exit of the Program.

Below is the implementation:

# Create a function to say count_maximumsqures() which takes the given base of the
# isosceles triangle and side of the square as the arguments and returns the
# count of the maximum number of squares of the given sidelength required that
# can be fitted inside the given isosceles triangle.


def count_maximumsqures(gvn_base, squre_side):
    # Inside the function, calculate the count of the maximum number of squares using the
    # above mathematical formula and store it in a variable.
    cnt = (gvn_base / squre_side - 1) * (gvn_base / squre_side) / 2
    # Return the above count value.
    return cnt


# Give the base of the triangle as static input and store it in a variable.
gvn_base = 8
# Give the side of the square as static input and store it in another variable.
squre_side = 3
print("The maximum number of squares with given sidelength that can be fitted inside the isosceles triangle = ")
# Pass the given base of the isosceles triangle and side of the square as the arguments
# to the count_maximumsqures() function, convert it into Integer using int()
# function, and print it.
print(int(count_maximumsqures(gvn_base, squre_side)))

Output:

The maximum number of squares with given sidelength that can be fitted inside the isosceles triangle = 
2

Method #2: Using Mathematical Formula (User Input)

Approach:

  • Give the base of the triangle as user input using the int(input()) function and store it in a variable.
  • Give the side of the square as user input using the int(input()) function and store it in another variable.
  • Create a function to say count_maximumsqures() which takes the given base of the isosceles triangle and side of the square as the arguments and returns the count of the maximum number of squares of the given sidelength required that can be fitted inside the given isosceles triangle.
  • Inside the function, calculate the count of the maximum number of squares using the above mathematical formula and store it in a variable.
  • Return the above count value.
  • Pass the given base of the isosceles triangle and side of the square as the arguments to the count_maximumsqures() function, convert it into Integer using int() function, and print it.
  • The Exit of the Program.

Below is the implementation:

# Create a function to say count_maximumsqures() which takes the given base of the
# isosceles triangle and side of the square as the arguments and returns the
# count of the maximum number of squares of the given sidelength required that
# can be fitted inside the given isosceles triangle.


def count_maximumsqures(gvn_base, squre_side):
    # Inside the function, calculate the count of the maximum number of squares using the
    # above mathematical formula and store it in a variable.
    cnt = (gvn_base / squre_side - 1) * (gvn_base / squre_side) / 2
    # Return the above count value.
    return cnt


# Give the base of the triangle as user input using the int(input()) function
# and store it in a variable.
gvn_base =  int(input("Enter some random number = "))
# Give the side of the square as user input using the int(input()) function and 
# store it in another variable.
squre_side =  int(input("Enter some random number = "))
print("The maximum number of squares with given sidelength that can be fitted inside the isosceles triangle = ")
# Pass the given base of the isosceles triangle and side of the square as the arguments
# to the count_maximumsqures() function, convert it into Integer using int()
# function, and print it.
print(int(count_maximumsqures(gvn_base, squre_side)))


Output:

Enter some random number = 5
Enter some random number = 2
The maximum number of squares with given sidelength that can be fitted inside the isosceles triangle = 
1

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 for Maximum Number of Squares that Can Fit in a Right Angle Isosceles Triangle Read More »

Program to Calculate Volume and Surface Area of Hemisphere

Python Program to Calculate Volume and Surface Area of Hemisphere

In the previous article, we have discussed Python Program to Calculate Volume of Dodecahedron
Given the radius value of the hemisphere, the task is to find the Volume and Surface Area of the given Hemisphere in Python.

Hemisphere:

It is the precise half of a sphere in geometry. Many real-life examples of hemispheres may be found, such as our planet Earth, which is divided into two hemispheres, the southern and northern hemispheres.

Examples:

Example1:

Input:

Given Radius of Hemisphere = 7

Output:

The Surface Area of the Hemisphere with radius { 7 } is = 307.8760800517997
The Volume of the Hemisphere with radius { 7 } is = 718.377520120866

Example2:

Input:

Given Radius of Hemisphere = 8

Output:

The Surface Area of the Hemisphere with radius { 8 } is = 402.1238596594935
The Volume of the Hemisphere with radius { 8 } is = 1072.330292425316

Program to Calculate Volume and Surface Area of Hemisphere

Below are the ways to Calculate the Volume and Surface Area of the Hemisphere in Python.

surface area of the Hemisphere = 2 pi r^2
volume of the Hemisphere = frac{2 pi r^2}{3}

Method #1: Using Mathematical Formula (Static Input)

Approach:

  • Import the math module using the math keyword.
  • Give the radius of the hemisphere as static input and store it in a variable.
  • We can get the pi value using the pi() function.
  • We can Calculate the power using the pow() function
  • Calculate the surface area of the hemisphere with the given radius using the above given mathematical formula
  • (2 pi r^2)and functions and store the result in some variable say hemiArea.
  • Calculate the volume of the hemisphere with the given radius using the above given mathematical formula
  • ( frac{2 pi r^2}{3})and functions and store the result in some variable say hemiVolume.
  • Print the hemiArea to get the Surface Area of the given hemisphere.
  • Print the hemiVolume to get the Volume of the given hemisphere.
  • The Exit of the Program.

Below is the implementation:

# Import the math module using the math keyword.
import math
# Give the radius of the hemisphere as static input and store it in a variable.
radiusHemi = 7
# We can get the pi value using the pi() function.
# We can Calculate the power using the pow() function
# Calculate the surface area of the hemisphere with the given radius
# using the above given mathematical formula
# and functions and store the result in some variable say hemiArea.
hemiArea = 2 * math.pi * math.pow(radiusHemi, 2)
# Calculate the volume of the hemisphere with the given radius
# using the above given mathematical formula
# and functions and store the result in some variable say hemiVolume.
hemiVolume = 2 * math.pi * math.pow(radiusHemi, 3) / 3
# Print the hemiArea to get the Surface Area of the given hemisphere.
print(
    'The Surface Area of the Hemisphere with radius {', radiusHemi, '} is =', hemiArea)
# Print the hemiVolume to get the Volume of the given hemisphere.
print(
    'The Volume of the Hemisphere with radius {', radiusHemi, '} is =', hemiVolume)

Output:

The Surface Area of the Hemisphere with radius { 7 } is = 307.8760800517997
The Volume of the Hemisphere with radius { 7 } is = 718.377520120866

Method #2: Using Mathematical Formula (User Input)

Approach:

  • Import the math module using the math keyword.
  • Give the radius of the hemisphere as user input using the int(input()) function and store it in a variable.
  • We can get the pi value using the pi() function.
  • We can Calculate the power using the pow() function
  • Calculate the surface area of the hemisphere with the given radius using the above given mathematical formula
  • (2 pi r^2)and functions and store the result in some variable say hemiArea.
  • Calculate the volume of the hemisphere with the given radius using the above given mathematical formula
  • ( frac{2 pi r^2}{3})and functions and store the result in some variable say hemiVolume.
  • Print the hemiArea to get the Surface Area of the given hemisphere.
  • Print the hemiVolume to get the Volume of the given hemisphere.
  • The Exit of the Program.

Below is the implementation:

# Import the math module using the math keyword.
import math
# Give the radius of the hemisphere as user input using the int(input()) function
# and store it in a variable.
radiusHemi = int(input('Enter some random radius of the Hemisphere = '))
# We can get the pi value using the pi() function.
# We can Calculate the power using the pow() function
# Calculate the surface area of the hemisphere with the given radius
# using the above given mathematical formula
# and functions and store the result in some variable say hemiArea.
hemiArea = 2 * math.pi * math.pow(radiusHemi, 2)
# Calculate the volume of the hemisphere with the given radius
# using the above given mathematical formula
# and functions and store the result in some variable say hemiVolume.
hemiVolume = 2 * math.pi * math.pow(radiusHemi, 3) / 3
# Print the hemiArea to get the Surface Area of the given hemisphere.
print(
    'The Surface Area of the Hemisphere with radius {', radiusHemi, '} is =', hemiArea)
# Print the hemiVolume to get the Volume of the given hemisphere.
print(
    'The Volume of the Hemisphere with radius {', radiusHemi, '} is =', hemiVolume)

Output:

Enter some random radius of the Hemisphere = 8
The Surface Area of the Hemisphere with radius { 8 } is = 402.1238596594935
The Volume of the Hemisphere with radius { 8 } is = 1072.330292425316

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 Calculate Volume and Surface Area of Hemisphere Read More »

Program to Calculate Volume of Dodecahedron

Python Program to Calculate Volume of Dodecahedron

In the previous article, we have discussed Python Program to Calculate Area and Perimeter of Equilateral Triangle
Given a side of a Dodecahedron, the task is to find the volume of the Dodecahedron in Python.

Examples:

Example1:

Input:

Given Side = 5

Output:

The Volume of the Dodecahedron with side { 5 } is =  957.8898700780791

Example2:

Input:

Given Side = 8

Output:

The Volume of the Dodecahedron with side { 8 } is = 3923.5169078398117

Program to Calculate Volume of Dodecahedron in Python

Below are the ways to calculate the volume of the given Dodecahedron  in Python:

Volume = (15 + 7√5)*s3/4  where s is the side of the Dodecahedron

Method #1: Using Mathematical Formula (Static Input)

Approach:

  • Import the math module using the math keyword.
  • Give the side of the Dodecahedron as static input and store it in a variable.
  • Calculate the volume of the Dodecahedron using the above mathematical formula ( (15 + 7√5)*s3/4).
  • We Calculate the √5 in the above formula using the sqrt() function.
  • We can calculate the s^3 using the pow() function or ‘**‘ operator.
  • By using the above functions we calculate the volume of the Dodecahedron and store it in a variable say volDode.
  • Print the volDode value.
  • The Exit of the Program.

Below is the implementation:

# Import the math module using the math keyword.
import math
# Give the side of the Dodecahedron as static input and store it in a variable.
sideval = 5
# Calculate the volume of the Dodecahedron using the above mathematical formula
# ( (15 + 7√5)*s3/4).
# We Calculate the √5 in the above formula using the sqrt() function.
# We can calculate the s^3 using the pow() function or '**' operator.
# By using the above functions we calculate the volume of the Dodecahedron
# and store it in a variable say volDode.
volDode = (((15 + (7 * (math.sqrt(5)))) / 4) * (math.pow(sideval, 3)))
# Print the volDode value.
print(
    'The Volume of the Dodecahedron with side {', sideval, '} is = ', volDode)

Output:

The Volume of the Dodecahedron with side { 5 } is =  957.8898700780791

Method #2: Using Mathematical Formula (User Input)

Approach:

  • Import the math module using the math keyword.
  • Give the side of the Dodecahedron as user input using the int(input()) function and store it in a variable.
  • Calculate the volume of the Dodecahedron using the above mathematical formula ( (15 + 7√5)*s3/4).
  • We Calculate the √5 in the above formula using the sqrt() function.
  • We can calculate the s^3 using the pow() function or ‘**‘ operator.
  • By using the above functions we calculate the volume of the Dodecahedron and store it in a variable say volDode.
  • Print the volDode value.
  • The Exit of the Program.

Below is the implementation:

# Import the math module using the math keyword.
import math
# Give the side of the Dodecahedron as user input using the int(input()) function
# and store it in a variable.
sideval = int(input('Enter some random side of Dodecahedron = '))
# Calculate the volume of the Dodecahedron using the above mathematical formula
# ( (15 + 7√5)*s3/4).
# We Calculate the √5 in the above formula using the sqrt() function.
# We can calculate the s^3 using the pow() function or '**' operator.
# By using the above functions we calculate the volume of the Dodecahedron
# and store it in a variable say volDode.
volDode = (((15 + (7 * (math.sqrt(5)))) / 4) * (math.pow(sideval, 3)))
# Print the volDode value.
print(
    'The Volume of the Dodecahedron with side {', sideval, '} is = ', volDode)

Output:

Enter some random side of Dodecahedron = 8
The Volume of the Dodecahedron with side { 8 } is = 3923.5169078398117

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

Python Program to Calculate Volume of Dodecahedron Read More »

Program to Calculate Area and Perimeter of Equilateral Triangle

Python Program to Calculate Area and Perimeter of Equilateral Triangle

In the previous article, we have discussed Python Program for Maximum Number of 2×2 Squares That Can be Fit Inside a Right Isosceles Triangle
Given the side length of the equilateral triangle and the task is to calculate the area and perimeter of the equilateral triangle with the given side length.

Equilateral triangle:

An equilateral triangle is one with equal sides and angles on all three sides. The internal angles of an equilateral triangle are all 60 degrees.

Formulas:

Let ‘a’ be the side length of the equilateral triangle.

Area = (sqrt(3)/4) * a * a

Perimeter = 3*a

Examples:

Example1:

Input:

Given side length = 8

Output:

The Area of Equilateral Triangle with the given side length [ 8 ] =  27.712813
The Perimeter of Equilateral Triangle with the given side length [ 8 ] =  24.000000

Example2:

Input:

Given side length = 5

Output:

The Area of Equilateral Triangle with the given side length [ 5 ] =  10.825318
The Perimeter of Equilateral Triangle with the given side length [ 5 ] =  15.000000

Program to Calculate Area and Perimeter of Equilateral Triangle in Python

Below are the ways to calculate the area and perimeter of the equilateral triangle with the given side length:

Method #1: Using Mathematical Formula (Static Input)

Approach:

  • Import the math module using the import keyword.
  • Give the side length as static input and store it in a variable.
  • Calculate the area of the equilateral triangle using the above mathematical formula given and store it in another variable.
  • Calculate the perimeter of the equilateral triangle using the above mathematical formula given and store it in another variable.
  • Print the area of the equilateral triangle for the given side length.
  • Print the perimeter of the equilateral triangle for the given side length.
  • The Exit of the Program.

Below is the implementation:

# Import the math module using the import keyword.
from math import *
# Give the side length as static input and store it in a variable.
gvn_side_len = 8
# Calculate the area of the equilateral triangle using the above mathematical formula
# given and store it in another variable.
rslt_area = (sqrt(3) / 4) * gvn_side_len * gvn_side_len
# Calculate the perimeter of the equilateral triangle using the above mathematical
# formula given and store it in another variable.
rslt_perimetr = 3 * gvn_side_len
# Print the area of the equilateral triangle for the given side length.
print(
    "The Area of Equilateral Triangle with the given side length [", gvn_side_len, "] = % f" % rslt_area)
# Print the perimeter of the equilateral triangle for the given side length.
print(
    "The Perimeter of Equilateral Triangle with the given side length [", gvn_side_len, "] = % f" % rslt_perimetr)

Output:

The Area of Equilateral Triangle with the given side length [ 8 ] =  27.712813
The Perimeter of Equilateral Triangle with the given side length [ 8 ] =  24.000000

Method #2: Using Mathematical Formula (User Input)

Approach:

  • Import the math module using the import keyword.
  • Give the side length as user input using the float(input()) function and store it in a variable.
  • Calculate the area of the equilateral triangle using the above mathematical formula given and store it in another variable.
  • Calculate the perimeter of the equilateral triangle using the above mathematical formula given and store it in another variable.
  • Print the area of the equilateral triangle for the given side length.
  • Print the perimeter of the equilateral triangle for the given side length.
  • The Exit of the Program.

Below is the implementation:

# Import the math module using the import keyword.
from math import *
# Give the side length as user input using the float(input()) function and
# store it in a variable.
gvn_side_len = float(input("Enter some random number = "))
# Calculate the area of the equilateral triangle using the above mathematical formula
# given and store it in another variable.
rslt_area = (sqrt(3) / 4) * gvn_side_len * gvn_side_len
# Calculate the perimeter of the equilateral triangle using the above mathematical
# formula given and store it in another variable.
rslt_perimetr = 3 * gvn_side_len
# Print the area of the equilateral triangle for the given side length.
print(
    "The Area of Equilateral Triangle with the given side length [", gvn_side_len, "] = % f" % rslt_area)
# Print the perimeter of the equilateral triangle for the given side length.
print(
    "The Perimeter of Equilateral Triangle with the given side length [", gvn_side_len, "] = % f" % rslt_perimetr)

Output:

Enter some random number = 5
The Area of Equilateral Triangle with the given side length [ 5.0 ] = 10.825318
The Perimeter of Equilateral Triangle with the given side length [ 5.0 ] = 15.000000

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 Calculate Area and Perimeter of Equilateral Triangle Read More »

Program for Maximum Number of 2×2 Squares That Can be Fit Inside a Right Isosceles Triangle

Python Program for Maximum Number of 2×2 Squares That Can be Fit Inside a Right Isosceles Triangle

In the previous article, we have discussed Python Program to Find Slope of a Line
Given the base of the isosceles triangle, the task is to find the count of the maximum number of 2*2 squares required that can be fixed inside the given isosceles triangle.

The side of the square must be parallel to the base of the given isosceles triangle.

Examples:

Example1:

Input:

Given base of triangle = 8

Output:

The maximum number of 2*2 squares required that can be fixed inside the given isosceles triangle =  6

Explanation:

Example2:

Input:

Given base of triangle = 6

Output:

The maximum number of 2*2 squares required that can be fixed inside the given isosceles triangle =  3

Program for Maximum Number of 2×2 Squares That Can be Fit Inside a Right Isosceles Triangle in python:

Below are the ways to find the count of the maximum number of 2*2 squares required that can be fixed inside the given isosceles triangle:

Method #1: Using Mathematical Formula (Static Input)

Approach:

  • Give the base of the triangle as static input and store it in a variable.
  • Create a function to say count_Squares() which takes the given base of the isosceles triangle as an argument and returns the count of the maximum number of 2*2 squares required that can be fixed inside the given isosceles triangle.
  • Inside the function, subtract 2 from the given base value as it is the extra part.
  • Store it in the same variable.
  • Divide the given base of the triangle by 2 since each square has a base length of 2.
  • Store it in the same variable.
  • Calculate the value of gvn_trianglebase * (gvn_trianglebase + 1) / 2 (Mathematical Formula) and store it in another variable.
  • Return the above result which is the count of the maximum number of 2*2 squares required that can be fixed inside the given isosceles triangle.
  • Pass the given base of the isosceles triangle to the count_Squares() function and print it.
  • The Exit of the Program.

Below is the implementation:

# Create a function to say count_Squares() which takes the given base of the isosceles
# triangle as an argument and returns the count of the maximum number of 2*2
# squares required that can be fixed inside the given isosceles triangle.


def count_Squares(gvn_trianglebase):
    # Inside the function, subtract 2 from the given base value as it is the extra part.
    # Store it in the same variable.

    gvn_trianglebase = (gvn_trianglebase - 2)
    # Divide the given base of the triangle by 2 since each square has a base length of 2.
    # Store it in the same variable.
    gvn_trianglebase = gvn_trianglebase // 2
    # Calculate the value of gvn_trianglebase * (gvn_trianglebase + 1) / 2
    # (Mathematical Formula) and store it in another variable.
    rslt = gvn_trianglebase * (gvn_trianglebase + 1) // 2
    # Return the above result which is the count of the maximum number of 2*2 squares
    # required that can be fixed inside the given isosceles triangle.
    return rslt


# Give the base of the triangle as static input and store it in a variable.
gvn_trianglebase = 6
# Pass the given base of the isosceles triangle to the count_Squares() function
# and print it.
print("The maximum number of 2*2 squares required that can be fixed inside the given isosceles triangle = ",
      count_Squares(gvn_trianglebase))

Output:

The maximum number of 2*2 squares required that can be fixed inside the given isosceles triangle =  3

Method #2: Using Mathematical Formula (User Input)

Approach:

  • Give the base of the triangle as user input using the int(input()) function and store it in a variable.
  • Create a function to say count_Squares() which takes the given base of the isosceles triangle as an argument and returns the count of the maximum number of 2*2 squares required that can be fixed inside the given isosceles triangle.
  • Inside the function, subtract 2 from the given base value as it is the extra part.
  • Store it in the same variable.
  • Divide the given base of the triangle by 2 since each square has a base length of 2.
  • Store it in the same variable.
  • Calculate the value of gvn_trianglebase * (gvn_trianglebase + 1) / 2 (Mathematical Formula) and store it in another variable.
  • Return the above result which is the count of the maximum number of 2*2 squares required that can be fixed inside the given isosceles triangle.
  • Pass the given base of the isosceles triangle to the count_Squares() function and print it.
  • The Exit of the Program.

Below is the implementation:

# Create a function to say count_Squares() which takes the given base of the isosceles
# triangle as an argument and returns the count of the maximum number of 2*2
# squares required that can be fixed inside the given isosceles triangle.


def count_Squares(gvn_trianglebase):
    # Inside the function, subtract 2 from the given base value as it is the extra part.
    # Store it in the same variable.

    gvn_trianglebase = (gvn_trianglebase - 2)
    # Divide the given base of the triangle by 2 since each square has a base length of 2.
    # Store it in the same variable.
    gvn_trianglebase = gvn_trianglebase // 2
    # Calculate the value of gvn_trianglebase * (gvn_trianglebase + 1) / 2
    # (Mathematical Formula) and store it in another variable.
    rslt = gvn_trianglebase * (gvn_trianglebase + 1) // 2
    # Return the above result which is the count of the maximum number of 2*2 squares
    # required that can be fixed inside the given isosceles triangle.
    return rslt


# Give the base of the triangle as user input using the int(input()) function
# and store it in a variable.
gvn_trianglebase = int(input("Enter some random number = "))
# Pass the given base of the isosceles triangle to the count_Squares() function
# and print it.
print("The maximum number of 2*2 squares required that can be fixed inside the given isosceles triangle = ",
      count_Squares(gvn_trianglebase))

Output:

Enter some random number = 8
The maximum number of 2*2 squares required that can be fixed inside the given isosceles triangle = 6

Find a comprehensive collection of Examples of Python Programs ranging from simple ones to complex ones to guide you throughout your coding journey.

Python Program for Maximum Number of 2×2 Squares That Can be Fit Inside a Right Isosceles Triangle Read More »

Program to Find Slope of a Line

Python Program to Find Slope of a Line

In the previous article, we have discussed Python Program for Section Formula (Point that Divides a Line in Given Ratio)
Given two points of a line, the task is to find the slope of a given line.

Let  A(x1,y1) and B(x2,y2) are the two points on a straight line.

Formula :

Formula to find the slope of a given line is:

slope=(y2-y1)/(x2-x1)

Examples:

Example1:

Input:

Given First Point = ( 5, 3  ) 
Given Second Point = ( 1, 2 )

Output:

The slope of the line for the given two points is :
0.25

Example2:

Input:

Given First Point = ( 5, 1 ) 
Given Second Point = ( 6, 2 )

Output:

The slope of the line for the given two points is :
1.0

Program to Find Slope of a Line in Python

Below are the ways to find the slope of a given line 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.
  • Pass the given two points of a line i.e, a1, a2, b1, b2, as the arguments to the Find_Slope() function.
  • Create a function to say Find_Slope() which takes the given two points of a line i.e, a1, a2, b1, b2 as the arguments and returns the slope of the given line.
  • Inside the function, calculate the slope of the line with the given two points using the above mathematical formula and convert it into float using the float() function.
  • Store it in a variable.
  • Return the above result i.e, the slope of the line.
  • The Exit of the Program.

Below is the implementation:

# Create a function to say Find_Slope() which takes the given two points of a line i.e,
# a1, a2, b1, b2 as the arguments and returns the slope of the given line.


def Find_Slope(a1, a2, b1, b2):
    # Inside the function, calculate the slope of the line with the given two points
    # using the above mathematical formula and convert it into float using the
    # float() function.

    # Store it in a variable.
    rslt_slope = (float)(b2-b1)/(a2-a1)
    # Return the above result i.e, the slope of the line.
    return rslt_slope


# Give the first point as static input and store it in two variables.
a1 = 5
b1 = 3
# Give the second point as static input and store it in another two variables.
a2 = 1
b2 = 2
print("The slope of the line for the given two points is :")
# Pass the given two points of a line i.e, a1, a2, b1, b2, as the arguments to the
# Find_Slope() function.
print(Find_Slope(a1, a2, b1, b2))

Output:

The slope of the line for the given two points is :
0.25

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.
  • Pass the given two points of a line i.e, a1, a2, b1, b2, as the arguments to the Find_Slope() function.
  • Create a function to say Find_Slope() which takes the given two points of a line i.e, a1, a2, b1, b2 as the arguments and returns the slope of the given line.
  • Inside the function, calculate the slope of the line with the given two points using the above mathematical formula and convert it into float using the float() function.
  • Store it in a variable.
  • Return the above result i.e, the slope of the line.
  • The Exit of the Program.

Below is the implementation:

# Create a function to say Find_Slope() which takes the given two points of a line i.e,
# a1, a2, b1, b2 as the arguments and returns the slope of the given line.


def Find_Slope(a1, a2, b1, b2):
    # Inside the function, calculate the slope of the line with the given two points
    # using the above mathematical formula and convert it into float using the
    # float() function.

    # Store it in a variable.
    rslt_slope = (float)(b2-b1)/(a2-a1)
    # Return the above result i.e, the slope of the line.
    return rslt_slope


# 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())
print("The slope of the line for the given two points is :")
# Pass the given two points of a line i.e, a1, a2, b1, b2, as the arguments to the
# Find_Slope() function.
print(Find_Slope(a1, a2, b1, b2))

Output:

Enter some random first point values separated by spaces = 5 1
Enter some random second point values separated by spaces = 6 2
The slope of the line for the given two points is :
1.0

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 Find Slope of a Line Read More »

Program for Section Formula (Point that Divides a Line in Given Ratio)

Python Program for Section Formula (Point that Divides a Line in Given Ratio)

In the previous article, we have discussed Python Program to Find the Mid-Point of a Line
Given two points of a line and P, Q, the task is to find the point that divides the line in the given ratio P: Q in Python.

The section formula gives us the coordinates of the point that divides a given line segment into two parts with lengths that are in the ratio m: n.

Section Formula:

(mx2+nx1)/(m+n), (my2+ny1)/(m+n)

Examples:

Example1:

Input:

Given First Point = ( 2, 4 )
Given Second Point = ( 1, 3 )
Given ratio value p= 1
Given ratio value q= 2

Output:

The point that divides the line in the given ratio ( 1 : 2 ) is :
( 1.6666666666666667 , 3.6666666666666665 )

Example2:

Input:

Given First Point = ( 5, 7)
Given Second Point = ( 2, 8 )
Given ratio value p= 2
Given ratio value q= 5

Output:

The point that divides the line in the given ratio ( 2 : 5 ) is :
( 4.142857142857143 , 7.285714285714286 )

Program for Section Formula (Point that Divides a Line in Given Ratio) in Python:

Below are the ways to find the point that divides the line in the given ratio P: Q 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 ratio values p, q as static input and store them in two separate variables.
  • Pass the given two points of a line and the ratio values i.e, a1, a2, b1, b2, p, q as the arguments to the Find_Section() function.
  • Create a function to say Find_Midpoint() which takes the given two points of a line and the ratio values i.e, a1, a2, b1, b2, p, q as the arguments and prints the point that divides the line in the given ratio p: q.
  • Inside the function calculate the x coordinate of the point using the mathematical formula (q * a1)+(p * a2))/(p + q) and convert it into float using the float() function.
  • Store it in a variable.
  • Calculate the y coordinate of the point using the mathematical formula (q * b1)+(p * b2))/(p + q) and convert it into float using the float() function.
  • Store it in another variable.
  • Print the point that divides the line in the given ratio p: q.
  • The Exit of the Program.

Below is the implementation:

# Create a function to say Find_Midpoint() which takes the given two points of a line
# and the ratio values i.e, a1, a2, b1, b2, p, q as the arguments and prints the point
# that divides the line in the given ratio p: q.


def Find_Section(a1, a2, b1, b2, p, q):
    # Inside the function calculate the x coordinate of the point using the mathematical
    # formula (q * a1)+(p * a2))/(p + q) and convert it into float
    # using the float() function.
    # Store it in a variable.
    x_coordinate = (float)((q * a1)+(p * a2))/(p + q)
    # Calculate the y coordinate of the point using the mathematical formula
    # (q * b1)+(p * b2))/(p + q) and convert it into float using the
    # float() function.
    # Store it in another variable.
    y_coordinate = (float)((q * b1)+(p * b2))/(p + q)

    # Print the point that divides the line in the given ratio p: q.
    print("(", x_coordinate, ",", y_coordinate, ")")


# Give the first point as static input and store it in two variables.
a1 = 2
b1 = 4
# Give the second point as static input and store it in another two variables.
a2 = 1
b2 = 3
p = 1
q = 2
print("The point that divides the line in the given ratio (", p, ":", q, ") is :")
# Pass the given two points of a line and the ratio values i.e, a1, a2, b1, b2, p, q as
# the arguments to the Find_Section() function.
Find_Section(a1, a2, b1, b2, p, q)

Output:

The point that divides the line in the given ratio ( 1 : 2 ) is :
( 1.6666666666666667 , 3.6666666666666665 )

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 ratio values p, q as static input and store them in two separate variables.
  • Pass the given two points of a line and the ratio values i.e, a1, a2, b1, b2, p, q as the arguments to the Find_Section() function.
  • Create a function to say Find_Midpoint() which takes the given two points of a line and the ratio values i.e, a1, a2, b1, b2, p, q as the arguments and prints the point that divides the line in the given ratio p: q.
  • Inside the function calculate the x coordinate of the point using the mathematical formula (q * a1)+(p * a2))/(p + q) and convert it into float using the float() function.
  • Store it in a variable.
  • Calculate the y coordinate of the point using the mathematical formula (q * b1)+(p * b2))/(p + q) and convert it into float using the float() function.
  • Store it in another variable.
  • Print the point that divides the line in the given ratio p: q.
  • The Exit of the Program.

Below is the implementation:

# Create a function to say Find_Midpoint() which takes the given two points of a line
# and the ratio values i.e, a1, a2, b1, b2, p, q as the arguments and prints the point
# that divides the line in the given ratio p: q.


def Find_Section(a1, a2, b1, b2, p, q):
    # Inside the function calculate the x coordinate of the point using the mathematical
    # formula (q * a1)+(p * a2))/(p + q) and convert it into float
    # using the float() function.
    # Store it in a variable.
    x_coordinate = (float)((q * a1)+(p * a2))/(p + q)
    # Calculate the y coordinate of the point using the mathematical formula
    # (q * b1)+(p * b2))/(p + q) and convert it into float using the
    # float() function.
    # Store it in another variable.
    y_coordinate = (float)((q * b1)+(p * b2))/(p + q)

    # Print the point that divides the line in the given ratio p: q.
    print("(", x_coordinate, ",", y_coordinate, ")")


# 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())
p = 2
q = 5
print("The point that divides the line in the given ratio (", p, ":", q, ") is :")
# Pass the given two points of a line and the ratio values i.e, a1, a2, b1, b2, p, q as
# the arguments to the Find_Section() function.
Find_Section(a1, a2, b1, b2, p, q)

Output:

Enter some random first point values separated by spaces = 5 7
Enter some random second point values separated by spaces = 2 8
The point that divides the line in the given ratio ( 2 : 5 ) is :
( 4.142857142857143 , 7.285714285714286 )

Access the big list of Python Programming Code Examples with actual logical code asked in Programming and Coding Interviews for Python and stand out from the crowd.

Python Program for Section Formula (Point that Divides a Line in Given Ratio) Read More »

Program to Find the Mid-Point of a Line

Python Program to Find the Mid-Point of a Line

In the previous article, we have discussed Python Program to Find Line Passing Through 2 Points
Given two points of a line (which are the start and endpoints) and the task is to find the midpoint of the given line in python.

The formula for the midpoint of a line:

Let the two points of a line are (x1, y2) and (x2, y2).

The formula for midpoint is:

Midpoint = ((x1+x2)/2 , (y1+y2)/2)

Examples:

Example1:

Input:

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

Output:

The Midpoint of the given line is:
( 3 , 3 )

Example2:

Input:

Given First Point = ( 6 , -2 )
Given Second Point = ( 7, 4 )

Output:

The Midpoint of the given line is:
( 6 , 1 )

Program to Find the Mid-Point of a Line in Python

Below are the ways to find the midpoint of the given line 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.
  • Pass the given two points of a line i.e, a1, a2, b1, b2 as the arguments to the Find_Midpoint() function.
  • Create a function to say Find_Midpoint() which takes the given two points of a line i.e, a1, a2, b1, b2 as the arguments, and prints the midpoint of the given line.
  • Calculate the x coordinate of the midpoint of the given line using the above given mathematical formula and store it in a variable.
  • Calculate the y coordinate of the midpoint of the given line using the above given mathematical formula and store it in another variable.
  • Print the midpoint of the given line.
  • The Exit of the Program.

Below is the implementation:

# Create a function to say Find_Midpoint() which takes the given two points of a line i.e,
# a1, a2, b1, b2 as the arguments, and prints the midpoint of the given line.


def Find_Midpoint(a1, a2, b1, b2):
    # Calculate the x coordinate of the midpoint of the given line using the above
    # given mathematical formula and store it in a variable.
    mid_x_Coordinate = (a1 + a2) // 2
    # Calculate the y coordinate of the midpoint of the given line using the above
    # given mathematical formula and store it in another variable.
    mid_y_Coordinate = (b1 + b2) // 2
    # Print the midpoint of the given line.
    print("(", mid_x_Coordinate, ",", mid_y_Coordinate, ")")


# Give the first point as static input and store it in two variables.
a1 = 3
b1 = 1
# Give the second point as static input and store it in another two variables.
a2 = 4
b2 = 5
print("The Midpoint of the given line is:")
# Pass the given two points of a line i.e, a1, a2, b1, b2 as the arguments to the
# Find_Midpoint() function.
Find_Midpoint(a1, a2, b1, b2)

Output:

The Midpoint of the given line is:
( 3 , 3 )

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.
  • Pass the given two points of a line i.e, a1, a2, b1, b2 as the arguments to the Find_Midpoint() function.
  • Create a function to say Find_Midpoint() which takes the given two points of a line i.e, a1, a2, b1, b2 as the arguments, and prints the midpoint of the given line.
  • Calculate the x coordinate of the midpoint of the given line using the above given mathematical formula and store it in a variable.
  • Calculate the y coordinate of the midpoint of the given line using the above given mathematical formula and store it in another variable.
  • Print the midpoint of the given line.
  • The Exit of the Program.

Below is the implementation:

# Create a function to say Find_Midpoint() which takes the given two points of a line i.e,
# a1, a2, b1, b2 as the arguments, and prints the midpoint of the given line.


def Find_Midpoint(a1, a2, b1, b2):
    # Calculate the x coordinate of the midpoint of the given line using the above
    # given mathematical formula and store it in a variable.
    mid_x_Coordinate = (a1 + a2) // 2
    # Calculate the y coordinate of the midpoint of the given line using the above
    # given mathematical formula and store it in another variable.
    mid_y_Coordinate = (b1 + b2) // 2
    # Print the midpoint of the given line.
    print("(", mid_x_Coordinate, ",", mid_y_Coordinate, ")")


# 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())
print("The Midpoint of the given line is:")
# Pass the given two points of a line i.e, a1, a2, b1, b2 as the arguments to the
# Find_Midpoint() function.
Find_Midpoint(a1, a2, b1, b2)

Output:

Enter some random first point values separated by spaces = 6 -2
Enter some random second point values separated by spaces = 7 4
The Midpoint of the given line is:
( 6 , 1 )

The best way to learn Python for Beginners is to practice as much as they can taking help of the Sample Python Programs For Beginners. Using them you can develop code on your own and master coding skills.

Python Program to Find the Mid-Point of a Line Read More »

Program to Find Line Passing Through 2 Points

Python Program to Find Line Passing Through 2 Points

In the previous article, we have discussed Python Program to Find N’th Pentagonal Number
Given two points P, Q in the coordinate plane and the task is to find the equation of the line passing through both the given points.

This type of conversion is very useful in many geometric algorithms such as line intersection, finding the circumcenter of a triangle, finding the incenter of a triangle, etc.

Let P(x1, y1) and Q(x2, y2) be the given two points. We can now find the equation of the line formed by these points.

Any line can be written as

ax + by = c

Let the two points form a straight line. As a result,

ax1 + by1 = c
ax2 + by2 = c

Formulas:

We can change the following values to ensure that all of the equations hold true:

a = y2 – y1
b = x1 – x2

c = ax1 + by1

Examples:

Example1:

Input:

Given First Point = ( 4 , 2 ) 
Given Second Point = ( 3 , 8 )

Output:

The Equation of line passing through the given two points is:  6 x +  1 y =  26

Example2:

Input:

Given First Point = ( 6 , 3 ) 
Given Second Point = ( 1 , 4 )

Output:

The Equation of line passing through the given two points is: 1 x + 5 y = 21

Program to Find Line Passing Through 2 Points in Python

Below are the ways to find the equation of the line passing through both the given points 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.
  • Subtract b1 from b2 and store it in another variable say p.
  • Subtract a2 from b1 and store it in another variable say q.
  • Calculate the value of p*(a1) + q*(b1) and store it in a variable say r.
  • Check if the value of q is less than 0 using the if conditional statement.
  • If it is true, then print the respective line equation using the variables p,q,r.
  • Else, print the respective line equation using the variables p,q,r.
  • The Exit of the Program.

Below is the implementation:

# Give the first point as static input and store it in two variables.
a1 = 4
b1 = 2
# Give the second point as static input and store it in another two variables.
a2 = 3
b2 = 8
# Subtract b1 from b2 and store it in another variable say p.
p = b2 - b1
# Subtract a2 from b1 and store it in another variable say q.
q = a1 - a2
# Calculate the value of p*(a1) + q*(b1) and store it in a variable say r.
r = p*(a1) + q*(b1)
# Check if the value of q is less than 0 using the if conditional statement.
if(q < 0):
  # If it is true, then print the respective line equation using the variables p,q,r.
    print("The Equation of line passing through the given two points is:",
          p, "x ", q, "y = ", r)
else:
  # Else, print the respective line equation using the variables p,q,r.
    print("The Equation of line passing through the given two points is: ",
          p, "x + ", q, "y = ", r)
#include <iostream>

using namespace std;

int main ( ) {
  int a1 = 4;
  int b1 = 2;
  int a2 = 3;
  int b2 = 8;
  double p = b2 - b1;
  double q = a1 - a2;
  double r = p * ( a1 ) + q * ( b1 );
  if ( ( q < 0 ) && ( r < 0 ) ) {
    cout << "The Equation of line passing through the given two points is:" << p << "x " << q << "y = " << r << endl;
  }
  else {
    cout << "The Equation of line passing through the given two points is: " << p << "x + " << q << "y = " << r << endl;
  }
  return 0;
}

Output:

The Equation of line passing through the given two points is:  6 x +  1 y =  26

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.
  • Subtract b1 from b2 and store it in another variable say p.
  • Subtract a2 from b1 and store it in another variable say q.
  • Calculate the value of p*(a1) + q*(b1) and store it in a variable say r.
  • Check if the value of q is less than 0 using the if conditional statement.
  • If it is true, then print the respective line equation using the variables p,q,r.
  • Else, print the respective line equation using the variables p,q,r.
  • 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())
# Subtract b1 from b2 and store it in another variable say p.
p = b2 - b1
# Subtract a2 from b1 and store it in another variable say q.
q = a1 - a2
# Calculate the value of p*(a1) + q*(b1) and store it in a variable say r.
r = p*(a1) + q*(b1)
# Check if the value of q is less than 0 using the if conditional statement.
if(q < 0):
  # If it is true, then print the respective line equation using the variables p,q,r.
    print("The Equation of line passing through the given two points is:",
          p, "x ", q, "y = ", r)
else:
  # Else, print the respective line equation using the variables p,q,r.
    print("The Equation of line passing through the given two points is: ",
          p, "x + ", q, "y = ", r)

Output:

Enter some random first point values separated by spaces = 6 3
Enter some random second point values separated by spaces = 1 4
The Equation of line passing through the given two points is: 1 x + 5 y = 21

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 Find Line Passing Through 2 Points Read More »

Program to Find Sum of Series 12!+23!+35!+.....N(N+1)!

Python Program to Find Sum of Series 1/2!+2/3!+3/5!+…..N/(N+1)!

In the previous article, we have discussed Python Program to Find Sum of Series 5^2+10^2+15^2+…..N^2
Given a number N and the task is to find the sum of series (1/2!+2/3!+3/5!+…..N/(N+1)!) 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 } =  0.9998015873015872

Example2:

Input:

Given Number (Limit) = 13

Output:

The above series sum till the given number N{ 13 } =  0.9999999999885293

Program to Find Sum of Series 1/2!+2/3!+3/5!+…..N/(N+1)!

Below are the ways to find the sum of series (1/2!+2/3!+3/5!+…..N/(N+1)!) 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 1.
  • Take another variable to say rsltseries_summ and initialize its value to 0.0 (Floating point number).
  • Loop until the above-declared variable itr value is less than or equal to the given number using the while loop.
  • Calculate the factorial of itr+1 using the math.factorial() method and store it in another variable.
  • Calculate the value of itr divided by the above result factorial and convert it into float using the float() function.
  • 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 1.
  • 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 itr and initialize its value to 1.
itr = 1
# Take a variable to say rsltseries_summ and initialize its value to 0.0
# (Floating point number)
rsltseries_summ = 0.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 factorial of itr+1 using the math.factorial() method and
    # store it in another variable.
    factrl = math.factorial(itr+1)
    # Calculate the value of itr divided by the above result factorial and convert it
    # into float using the float() function.
    # Store it in another variable.
    p = float(itr/factrl)
    # Add the above result to the rsltseries_summ and store it in the same variable.
    rsltseries_summ += p
    # Increment the above itr value by 1.
    itr += 1
# 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 } =  0.9998015873015872

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 1.
  • Take another variable to say rsltseries_summ and initialize its value to 0.0 (Floating point number).
  • Loop until the above-declared variable itr value is less than or equal to the given number using the while loop.
  • Calculate the factorial of itr+1 using the math.factorial() method and store it in another variable.
  • Calculate the value of itr divided by the above result factorial and convert it into float using the float() function.
  • 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 1.
  • 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 1.
itr = 1
# Take a variable to say rsltseries_summ and initialize its value to 0.0
# (Floating point number)
rsltseries_summ = 0.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 factorial of itr+1 using the math.factorial() method and
    # store it in another variable.
    factrl = math.factorial(itr+1)
    # Calculate the value of itr divided by the above result factorial and convert it
    # into float using the float() function.
    # Store it in another variable.
    p = float(itr/factrl)
    # Add the above result to the rsltseries_summ and store it in the same variable.
    rsltseries_summ += p
    # Increment the above itr value by 1.
    itr += 1
# 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 = 13
The above series sum till the given number N{ 13 } = 0.9999999999885293

If you are learning Python then the Python Programming Example is for you and gives you a thorough description of concepts for beginners, experienced programmers.

Python Program to Find Sum of Series 1/2!+2/3!+3/5!+…..N/(N+1)! Read More »