I am new to programming and I am trying to create a random number iterator that will take in a numpy random range and count how many times each individual number from 1-10 appears.
Example: random range goes from 1 to 5 and it will count how many times the #s appear. count1 appears once, count2 appears 3 times and count 9 appears once.
code:
import numpy as np
x1 = np.random.random(10)
count1 = 0
count2 = 0
count3 = 0
count4 = 0
count5 = 0
count6 = 0
count7 = 0
count8 = 0
count9 = 0
count10 = 0
for x in range(1,x1):
if x == 1:
count1 += count1
elif x == 2:
count2 += count2
elif x == 3:
count3 += count3
elif x == 4:
count4 += count4
elif x == 5:
count5 += count5
elif x == 6:
count6 += count6
elif x == 7:
count7 += count7
elif x == 8:
count8 += count8
elif x == 9:
count9 += count9
elif x == 10:
count10 += count10
print(count1)
print(count2)
print(count3)
print(count4)
print(count5)
print(count6)
print(count7)
print(count8)
print(count9)
print(count10)
Aucun commentaire:
Enregistrer un commentaire