Answer:
import random
count0, count1, count2, count3,
count4, count5, count6, count7,
count8, count9, i = [0 for _ in range(11)]
while i < 1000:
number = random.randint(0,9)
if number == 0:
count0 = count0 + 1
if number == 1:
count1 = count1 + 1
if number == 2:
count2 = count2 + 1
if number == 3:
count3 = count3 + 1
if number == 4:
count4 = count4 + 1
if number == 0:
count5 = count5 + 1
if number == 6:
count6 = count6 + 1
if number == 7:
count7 = count7 + 1
if number == 0:
count8 = count8 + 1
if number == 9:
count9 = count9 + 1
i = i+1
print("0's: "+ str(count0) + "\n"+ "1's: "+ str(count1) + "\n"+
"2's: "+ str(count2) + "\n"+ "3's: "+ str(count3) + "\n"+
"4's: "+ str(count4) + "\n"+ "5's: "+ str(count5) + "\n"+
"6's: "+ str(count6) + "\n"+ "7's: "+ str(count7) + "\n"+
"8's: "+ str(count8) + "\n"+ "9's: "+ str(count9) + "\n")
Explanation:
- Initialize variables to hold the count for each number
- Initialize <em>i</em> to control the while loop
- Inside the while loop, check for the numbers and increment the count values when matched.
- Print the result