Question: in python please 'numbers.txt is 1 2 3 4 5 6 7 8 9 10 11 15 99 100001 100019 99999989 99999991 Question 1 (6

 in python please 'numbers.txt" is 1 2 3 4 5 6

in python please

'numbers.txt" is

1 2 3 4 5 6 7 8 9 10 11 15 99 100001 100019 99999989 99999991

Question 1 (6 points): Purpose: To practice reading from a file and using a dictionary as a mapping Degree of Difficulty: Easy Caching is a very powerful technique in computer science. The technique simply involves recording the result of a complex calculation rather than re-computing that result every time it is needed. It may or may not surprise you to hear that there is no known formula for determinining whether or not a given number N is prime or not. More or less, the only way to know is to try dividing N by all integers between 1 and itself and seeing if any of them yield a remainder. For large N, this is a time-consuming computation, and therefore a good example of something that might be cached for some problems. For this question, your task is to write a program that takes a given set of numbers, determines whether each of them is prime, and caches the result using a dictionary. Provided Files On the course website, you will find a starter file that already contains an implementation of a function called is_prime(), which accepts a positive integer and returns a Boolean value indicating whether or not that integer is prime. You can keep this provided function and use it in your program. You will also find a sample input file, numbers.txt. It contains some positive integers, one per line of the file. You can use this to test your program, but keep in mind that your program must work for ANY similarly- formatted input file. Write a Function Write a function that takes a file name as its only parameter. The function should open the given file, read the numbers in it, and call the provided is prime() function to determine whether each number is prime. The results of this process should be stored in a dictionary. The keys for this dictionary should be the numbers from the file, and the value for each key should be the Boolean result indicating whether the matching key is a prime number or not. The function should return this dictionary. Print the results Call the function you wrote, using "numbers.txt" as the argument. Print the returned dictionary to the console. Sample Run Your output might look something like this: {1: False, 2: True, 3: True, 4: False, 5: True, 6: False, 7: True, 8: false, 9: False 10: False, 11: True, 15: False, 99: False, 100001: False , 100019: True, 99999989: True, 99999991: False}

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!