Question: In python 3 I need help writing a script that asks the user for a positive integer between 1 and 1,000. I need the script
In python 3 I need help writing a script that asks the user for a positive integer between 1 and 1,000. I need the script to print out a list of the prime numbers which are factors of the input value. Without using lambda
As an example: limit the examination to the first 11 prime numbers:
2 3 5 7 11 13 17 19 23 29 31
These first eleven prime numbers shall be stored in a global tuple.
Write a function that will accept an integer as a parameter. The function will print out the (partial) list prime factors of the input number. Using an appropriate looping statement to process through all eleven prime numbers. Print out each value which is a factor of the input (parameter) value. possibly using the remainder operation
In the main function, ask the user for an integer value between 1 and 1,000, inclusive. Convert the input value to int. (You can assume that the user will type in an acceptable value, at this point.) Pass this int value as the argument when you call your function to print out a partial list of prime factors.
Include simple input validation in your function to make sure that the user's input is acceptable, that is, between 1 and 1,000, inclusive. If the user input value is ok, call your function to print out the partial list of prime factors. If it is not, print out an error message instead and end the program.
Here is a sample run. The user input is shown in blue bold text.
output:
Enter a positive integer between 1 and 1,000: 12 2 is a factor of 12. 3 is a factor of 12.
Notice that the output is not a prime factorization of the input value. That would be 2 2 3.
I know the remainder operation will be helpful.lso notice that the minimal implementation does not get all of the factors of the input number either.
Enter a positive integer between 1 and 1,000: 82 2 is a factor of 82.
The correct solution would also list the prime number, 41. Both of these shortcomings are addressed in the Standard assignment.
Testing the code
Main needs to be updated to test this. Before asking the user for a numeric value and calling your function, call your function with some "known" int values. This way you can check to make sure that the function is working correctly.
For testing purposes, "hard code" some calls in the main function to your factors function. That way you have some repeated input values that you can use to check that the factors function is working the way you expect.
some of my pseudo code as an idea:
def main(): # hard-coded test cases factors(12) factors(60) # code to prompt the user for input # perform input validation # call the factors function
You have two tasks for your function are that the function that prints out the primes and input validation code. testing them both.
All together, there should be 8 test cases. Include the test cases, with the expected results, Only two of the test cases shall test input validation.
The the test cases can be very simple example
Test cases: 12: 2 3
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
