Reputation: 3
*#Function to find out maximum and minimum marks #From a list input, then passed as an argument into the function *
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]
Upvotes: 0
Views: 884
Reputation: 1848
You are almost there, but you make the entering of mymarks
more complicated than needed.
Instead of using *args
, just use plain args. And instead of the map
, just call split()
on the input value. split
already returns a list.
def marks(args):
print(args)
print(max(args))
print(min(args))
# marks input
mymarks = input("Enter the marks of all subjects: ").split()
marks(mymarks)
Upvotes: 0
Reputation: 170
Instead of using *args
declare a variable like def marks(m)
or use args[0]
.
Declaring variable will be the best as you can then just use max(m)
to get the max value in list.
Your function sets max of args which is a tuple. Your list is inside that tuple.
Happy coding.
Upvotes: 1