﻿ Python: Find maximum and the minimum value in a set - w3resource # Python: Find maximum and the minimum value in a set

## Python sets: Exercise-14 with Solution

Write a Python program to find maximum and the minimum value in a set.

Sample Solution:

Python Code:

``````#Create a set
setn = {5, 10, 3, 15, 2, 20}
print("Original set elements:")
print(setn)
print(type(setn))
print("\nMaximum value of the said set:")
print(max(setn))
print("\nMinimum value of the said set:")
print(min(setn))
```
```

Sample Output:

```Original set elements:
{2, 3, 5, 10, 15, 20}
<class 'set'>

Maximum value of the said set:
20

Minimum value of the said set:
2
```

Pictorial Presentation: ## Visualize Python code execution:

The following tool visualize what the computer is doing step-by-step as it executes the said program:

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz

﻿

## Python: Tips of the Day

While-else construct:

```i = 5

while i > 1:
print("Whil-ing away!")
i -= 1
if i == 3:
break
else:
print("Finished up!")
```