Coding homework · Variables and expressions · about 30 minutes
The prime number vault
A vault uses two five-digit prime numbers, 10007 and 10009. Store them in variables named p and q. Use an expression to multiply them, save the result, and print it. Then change only q to another prime, 10037, and calculate again.
Plan about 15–20 minutes for the products and comparison, then 10–15 minutes for the remainder trail. Complete both parts before submitting.
Part 1 · products and comparison
- Before running, write a comment estimating how many digits the first product will have.
- Save
10007inpand10009inq. Calculatep * q, save the product, and print it. - Update
qto10037. Calculate and print the new product. Keep the first product in a separate variable. - Use the two saved products to calculate and print how much the product changed.
Part 2 · remainder trail
In Python, a % b gives the remainder after dividing a by b. Use that arithmetic expression for three steps. Save each remainder in a new variable; no loop is needed.
- Reset
qto10009. Find and print the remainder ofq ÷ p. - Find and print the remainder of
p ÷ first remainder. - Find and print the remainder of
first remainder ÷ second remainder. The last nonzero remainder is the greatest common divisor.
100160063 100440259 280196 2 1 0
Run your code and check all six output lines. Then write your name and submit your code for teacher review.
This homework uses variables, arithmetic expressions, assignment, comments, and print. The remainder operator is explained here as one more arithmetic expression. The TODO comments show where to start; you can edit the whole program.
Run your code to see its output.
Submit to your teacher
Write your name for this submission. Your code, name, result, and time will be saved for teacher review.