Introduction to Programming using Python 1st Edition

Published by Pearson
ISBN 10: 0132747189
ISBN 13: 978-0-13274-718-9

Chapter 10 - Lists - Programming Exercises - Page 350: 10.7

Answer

code

Work Step by Step

# 10.7 (Count single digits) 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.) import random lst = [] for i in range(1000): lst.append(random.randint(0, 9)) counts = [] for i in range(10): counts.append(lst.count(lst[i])) for i in range(10): print(i, ":", counts[i], "times")
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.