Question: Write a Python program that will read the names contained in names.txt and insert them into a dictionary. They key values will be integers such

Write a Python program that will read the names contained in names.txt and insert them into a dictionary. They key values will be integers such that the first name will have key value 1, the second will have key value 2, the third will have key value 3 etc. Once the dictionary has been constructed, go through it and write the names that have prime key values into a new file called namesprime.txt. That is, only the names that have a key which is a prime number are written to namesprime.txt. You will have to create a function to determine whether an integer is prime or not. One way is to create an array of primes between 2 and 57 and check the value against those values. Another way is to go through all integers less than the key value and see if they divide it (really you only need to check integers from 2 to sqrt(number) to determine if its prime).

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!