编写一个 Python 程序来查找最大或最大集合项。这里,我们使用设置最大值功能来打印最大的设置项目。
# Set Max Item
mxSet = {25, 67, 36, 98, 11, 32, 19, 80, 91}
print("Set Items = ", mxSet)
print("Largest Item in mxSet Set = ", max(mxSet))
Python 最大集数输出
Set Items = {32, 98, 67, 36, 11, 80, 19, 25, 91}
Largest Item in mxSet Set = 98
寻找集合中最大项目的 Python 程序
这个 Python 示例允许输入设置的项目。接下来,我们使用集合排序函数(sorted(mxSet))对集合进行升序排序。接下来,我们打印最后一个索引位置项。我们可以使用索引值,因为排序函数返回一个列表。
# Set Max Item
mxSet = set()
number = int(input("Enter the Total Set Items = "))
for i in range(1, number + 1):
value = int(input("Enter the %d Set Item = " %i))
mxSet.add(value)
print("Set Items = ", mxSet)
sortedVal = sorted(mxSet)
print("Largest Item in mxSet Set = ", sortedVal[len(mxSet) - 1])
print("Data Type of sortedVal = ", type(sortedVal))
在这个 Python 程序中,我们创建了一个最大集合函数来打印最大集合数。if 语句(If(设置最大值< i)) checks whether the setLargest value is less than any of the set items. If True, assign that item as the largest 设置项。
# Set Max Item
def SetLargest(mxSet, setLargest):
for i in mxSet:
if(setLargest < i):
setLargest = i
return setLargest
mxSet = set()
number = int(input("Enter the Total Set Items = "))
for i in range(1, number + 1):
value = int(input("Enter the %d Set Item = " %i))
mxSet.add(value)
setLargest = value
print("Set Items = ", mxSet)
lar = SetLargest(mxSet, setLargest)
print("Largest Item in mxSet Set = ", lar)
巨蟒最大设定物品输出
Enter the Total Set Items = 4
Enter the 1 Set Item = 99
Enter the 2 Set Item = 122
Enter the 3 Set Item = 33
Enter the 4 Set Item = 100
Set Items = {33, 122, 99, 100}
Largest Item in mxSet Set = 122