Python Program To Find Maximum And Minimum Number In A Set
Chapter:
Python
Last Updated:
04-10-2023 17:57:37 UTC
Program:
/* ............... START ............... */
# Create a set
number_set = {10, 5, 15, 20, 3}
# Find the maximum and minimum numbers in the set
maximum_number = max(number_set)
minimum_number = min(number_set)
# Print the results
print(f"The maximum number in the set is: {maximum_number}")
print(f"The minimum number in the set is: {minimum_number}")
/* ............... END ............... */
Output
The maximum number in the set is: 20
The minimum number in the set is: 3
These are the maximum and minimum numbers in the number_set set. You can replace the elements in the
set with your own set of numbers to find the maximum and minimum values in your specific set.
Notes:
-
Please find the step followed in this program.
- First we create a set named number_set containing some numbers.
- Next step we use the max() function to find the maximum number in the set and store it in the maximum_number variable.
- We use the min() function to find the minimum number in the set and store it in the minimum_number variable.
- Finally, we print out the maximum and minimum numbers.
Tags
Python program to find maximum and minimum number in a Set #How do you find the minimum and maximum value of a Set?