Home > Software design >  How to count how many maximum numbers there are among inputted in one line values?
How to count how many maximum numbers there are among inputted in one line values?

Time:10-20

I've got 4 integer inputs in one line separated by a space, and I have to output the largest of them and how many largest integers there are, also in one line and separated by a space. The first request can be easily done with a max function, however I can't figure out how to do the second one. Example:

Input: 6 4 -3 6

Output: 6 2

And this is code I've written so far:

a, b, c, d = map(int, input().split())
max = max(a,b,c,d)
print(max, )

How can I count the amount of largest integers?

CodePudding user response:

Here is a way to do it:

x = "6 4 -3 6"
l = list(map(int, x.split()))
print(max(l), l.count(max(l)))

Where x is the string that you got from the call to input().

  • Related