0

Q1. Write a program that reads a specified number of integers and finds the ones that have the most occurrences.

For example, if you enter 2 3 40 3 5 4 –3 3 3 2 0, the number 3 occurs most often. If not one but several numbers have the most occurrences, all of them should be reported. For example, since 9 and 3 appear twice in the list 9 30 3 9 3 2 4, both occurrences should be reported.

9th Mar 2021, 4:16 AM
Ajay Kumar
8 odpowiedzi
+ 1
Hi! Please, show us your attempt.
9th Mar 2021, 4:47 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
Seems to be your homework. Anyways post what you have tried so far
9th Mar 2021, 4:56 AM
Atul [Inactive]
+ 1
I am writing a program that take the name of the book for example Harry Potter and output H12 with 12 the length of the name can anyone help
9th Mar 2021, 8:39 PM
Houssem Kitar
Houssem Kitar - avatar
+ 1
Calvin Sheen Thomas he is referring to task 52 of the python core module project " book titles"
10th Mar 2021, 6:44 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
Here's the solution: a, b = input().split(), [0, []] for x in range(len(a)): if (c:=a.count(a[x])) > b[0]: b = [a.count(a[x]), [a[x]]] elif c == b[0]: b[1].append(a[x]) for x in set(b[1]): print(x, end=" ") # Let me know of any bugs in my code
9th Mar 2021, 9:14 AM
Calvin Thomas
Calvin Thomas - avatar
0
#3 lines only with builtin str count method. Don't understand why don't you search for it by your self. 🤔 num = input("enter each num separated by space : ") occ = input("enter occ: ") print(num.count(occ))
9th Mar 2021, 10:25 AM
iTech
iTech - avatar
0
Houssem Kitar I suppose that I can help, if you provide me with the complete question.
10th Mar 2021, 2:13 AM
Calvin Thomas
Calvin Thomas - avatar
0
Houssem Kitar, file = open("/usercode/files/books.txt", "r") file = (file.read()).split("\n") for a in file: print(a[0] + str(len(a))) # Hope this helps
10th Mar 2021, 7:52 AM
Calvin Thomas
Calvin Thomas - avatar