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 1:
How many numbers?: 5
[4, 6, 8, 3, 3]
1-4
1-6
2-3
I need the code to have an output stated above.
import random
n = int(input("How many numbers?: "))
arr=[]
count = [0] * 9
for i in range(n):
arr.append(random.randint(1, 9))
count[arr[i]-1] += 1
print(arr)
for i in range(8):
if count[i] > 0:
print(f"{count[i]} - {i+1}")
Comments
Leave a comment