Answer to Question #314355 in Python for Kenjie

Question #314355

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-20T07:38:44-0400
from random import randint

count = int(input("How many numbers?: "))
array = [randint(1, 9) for i in range(count)]
print(array)
dictionary = {}
for i in range(count):
    if(array[i] in dictionary):
        dictionary[array[i]] += 1
    else:
        dictionary[array[i]] = 1
print(dictionary)

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