Ask Question
21 September, 08:22

Write a program that generates 1,000 random integers between 0 and 9 and displays the count for each number. (Hint: Use a list of ten integers, say counts, to store the counts for the number of 0s, 1s, ..., 9s.)

+2
Answers (1)
  1. 21 September, 09:57
    0
    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 i to control the while loop

    - Inside the while loop, check for the numbers and increment the count values when matched.

    - Print the result
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a program that generates 1,000 random integers between 0 and 9 and displays the count for each number. (Hint: Use a list of ten ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers