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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started