Answer to Question #314260 in Python for Harley

Question #314260

Frequency of Numbers


Develop a Python application that will randomly select n integers from 1 to 9 and will count the number of occurrence of the numbers without using the Counter from collections library.


Sample Output:


How many numbers?: 7


[2, 6, 8, 2, 1, 1,6]


2-2


2-6


1-8


2-1

1
Expert's answer
2022-03-19T04:13:49-0400
import random

n = int(input("How many numbers?: "))
arr=[]
rep=[]
for i in range(n):
   arr.append(random.randint(1, 9))
print(arr)
for i in range(n):
   cnt = 0;
   for j in range(i,n):
      if arr[i] == arr[j]:
         cnt += 1
   if arr[i] not in rep:
      rep.append(arr[i])
      print(f"{cnt} - {arr[i]}")
     

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS