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.
8 Antworten
+ 1
Hi! Please, show us your attempt.
+ 1
Seems to be your homework. Anyways post what you have tried so far
+ 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
+ 1
Calvin Sheen Thomas he is referring to task 52 of the python core module project " book titles"
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
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))
0
Houssem Kitar I suppose that I can help, if you provide me with the complete question.
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