Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a dictionary that has the integers from 1 through 100 as keys, and for each key, contains a list of all the integers that

Create a dictionary that has the integers from 1 through 100 as keys, and for each key, contains a list of all the integers that are factors of that key. For instance, for the integers from 1 through five, the dictionary should contain:

{1:[1], 2:[1,2], 3:[1,3], 4:[1,2,4], 5:[1,5]}

Do this for 1 through 100.

Hint 1: You may want to use nested for-loops, where the length of the inner loop depends on the value from the outer loop.

Hint 2: You can use the % (modulo) operator to determine whether one number divides into another.

In order to work through this assignment, youll need to create nested for-loops (one loop inside the other). Before the outer loop, youll need to create a dictionary {} to store the final result. The outer loop should iterate the key from 1 through 100, inclusive. Then each time through the outer loop youll want to create an empty list that will store all the factors of key.

Next, the inner for-loop will iterate value from 1 through key, inclusive. If key % value is zero, then append value to the list. (There is no need for an else statement.) Once you finish the inner loop, but still inside the outer loop, youll add an new entry to the dictionary, with key as the key, and the list as the value.

You may cut and paste the working code in the assignment text window, or you may save as a file and attach to the assignment submission.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions