Program for Product of Maximum in First array and Minimum in Second

Python Program for Product of Maximum in First array and Minimum in Second

In the previous article, we have discussed Python Program to Count Divisors of Factorial
Given two lists, the task is to find the product of maximum in the given first list and minimum in the given second list.

Examples:

Example 1:

Input:

Given the First List = [1, 2, 3, 4, 5]
Given the Second List = [2, 6, 7, 8, 9, 1]

Output:

The maximum element in given first list [1, 2, 3, 4, 5] = 5
The minimum element in given second list [2, 6, 7, 8, 9, 1] = 1
The product of max_in_fstlst and min_in_seclst [ 5 * 1 ] = 5

Example 2:

Input:

Given the First List = [10, 20, 30, 40, 50] 
Given the Second List = [1, 2, 3, 4, 5]

Output:

The maximum element in given first list [10, 20, 30, 40, 50] = 50
The minimum element in given second list [1, 2, 3, 4, 5] = 1
The product of max_in_fstlst and min_in_seclst [ 50 * 1 ] = 50

Program for Product of Maximum in First array and Minimum in Second in Python

Below are the ways to find the product of maximum in the given first list and minimum in the given second list.

Method #1: Using max() and min() Functions (Static Input)

Approach:

  • Give the first list as static input and store it in a variable.
  • Give the second list as static input and store it in another variable.
  • Find out the maximum element in the given first list using the built-in max() method and store it in another variable.
  • Find out the minimum element in the given second list using the built-in min() method and store it in another variable.
  • Multiply both the above obtained maximum element in the first list and minimum element in the given second list and store it in another variable.
  • Print the maximum element in the given first .
  • Print the minimum element in the given second list.
  • Print the Product of maximum element in the given first and minimum element in the given second list.
  • The Exit of the Program.

Below is the implementation:

# Give the first list as static input and store it in a variable.
fst_lst = [1, 2, 3, 4, 5]
# Give the second list as static input and store it in another variable.
secnd_lst = [2, 6, 7, 8, 9, 1]
# Find out the maximum element in the given first list using the built-in max() method
# and store it in another variable.
max_in_fstlst = max(fst_lst)
# Find out the minimum element in the given second list using the built-in min() method
# and store it in another variable.
min_in_seclst = min(secnd_lst)
# Multiply both the above obtained maximum element in the first list and minimum element
# in the given second list and store it in another variable.
prodct = max_in_fstlst*min_in_seclst
# Print the maximum element in the given first .
print("The maximum element in given first list", fst_lst, "=", max_in_fstlst)
# Print the minimum element in the given second list.
print("The minimum element in given second list", secnd_lst, "=", min_in_seclst)
# Print the Product of maximum element in the given first and minimum element in
# the given second list.
print("The product of max_in_fstlst and min_in_seclst [",
      max_in_fstlst, "*", min_in_seclst, "] =", prodct)

Output:

The maximum element in given first list [1, 2, 3, 4, 5] = 5
The minimum element in given second list [2, 6, 7, 8, 9, 1] = 1
The product of max_in_fstlst and min_in_seclst [ 5 * 1 ] = 5

Method #2: Using max() and min() Functions (User Input)

Approach:

  • Give the first list as user input using list(),map(),input(),and split() functions and store it in a variable
  • Give the second list as user input using list(),map(),input(),and split() functions and store it in another variable.
  • Find out the maximum element in the given first list using the built-in max() method and store it in another variable.
  • Find out the minimum element in the given second list using the built-in min() method and store it in another variable.
  • Multiply both the above obtained maximum element in the first list and minimum element in the given second list and store it in another variable.
  • Print the maximum element in the given first .
  • Print the minimum element in the given second list.
  • Print the Product of maximum element in the given first and minimum element in the given second list.
  • The Exit of the Program.

Below is the implementation:

# Give the first list as user input using list(),map(),input(),and split() functions and
# store it in a variable
fst_lst = list(map(int, input(
   'Enter some random List Elements separated by spaces = ').split()))
# Give the second list as user input using list(),map(),input(),and split() functions and
# store it in another variable.
secnd_lst = list(map(int, input(
   'Enter some random List Elements separated by spaces = ').split()))
# Find out the maximum element in the given first list using the built-in max() method
# and store it in another variable.
max_in_fstlst = max(fst_lst)
# Find out the minimum element in the given second list using the built-in min() method
# and store it in another variable.
min_in_seclst = min(secnd_lst)
# Multiply both the above obtained maximum element in the first list and minimum element
# in the given second list and store it in another variable.
prodct = max_in_fstlst*min_in_seclst
# Print the maximum element in the given first .
print("The maximum element in given first list", fst_lst, "=", max_in_fstlst)
# Print the minimum element in the given second list.
print("The minimum element in given second list", secnd_lst, "=", min_in_seclst)
# Print the Product of maximum element in the given first and minimum element in
# the given second list.
print("The product of max_in_fstlst and min_in_seclst [",
      max_in_fstlst, "*", min_in_seclst, "] =", prodct)

Output:

Enter some random List Elements separated by spaces = 4 1 4 2 6 8
Enter some random List Elements separated by spaces = 8 2 4 1 0 -1
The maximum element in given first list [4, 1, 4, 2, 6, 8] = 8
The minimum element in given second list [8, 2, 4, 1, 0, -1] = -1
The product of max_in_fstlst and min_in_seclst [ 8 * -1 ] = -8

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