如何从作为参数传递给函数的列表中找到最小值和最大值?我想找到列表的最小值和最大值但没有得到输出

How to find min and max value from a list that is passed on to a function as argument? I want to find min and max of list but not getting the output

*#查找最大最小标记的函数 #从列表输入,然后作为参数传递给函数 *

def marks(*args):
    print(args)
    print(max(args))
    print(min(args))

#marks input
mymarks = list(map(int,input("Enter the marks of all subjects: ").split()))
**#function call**
marks(mymarks)

Output:
Enter the marks of all subjects: 67 77 89 56 40
([67, 77, 89, 56, 40],)
[67, 77, 89, 56, 40]
[67, 77, 89, 56, 40]

而不是使用 *args 声明一个变量,如 def marks(m) 或使用 args[0].

声明变量将是最好的,因为您可以使用 max(m) 来获取列表中的最大值。

你的函数设置了元组的最大参数。你的列表在那个元组里面。

编码愉快。

您快完成了,但是您使 mymarks 的输入比需要的更复杂。

不要使用 *args,只需使用普通参数。而不是 map,只需对输入值调用 split()split 已经 returns 个列表。

def marks(args):
    print(args)
    print(max(args))
    print(min(args))


# marks input
mymarks = input("Enter the marks of all subjects: ").split()
marks(mymarks)