Question: Python code: Create an empty dictionary called dictCounts Initialize dictCounts. The dictionary should have one key for each digit 1 - 9. The initial value

Python code:

Create an empty dictionary called dictCounts

Initialize dictCounts. The dictionary should have one key for each digit 1 - 9. The initial value stored for each key should be be zero.

For each sale amount in the list:

Extract first digit of amount.

If first digit is n, add 1 to the count stored for key n in the dictionary.

Create a new empty dictionary called dictPercents.

Use dictCounts to create the keys and values in dictPercents. The keys in dictPercents should be 1, 2, ... 9. The values should be the percentages. For example, dictPercents[2] should be the percent of times 2 was the first digit in the data.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!