

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


AP CSP · Unit 2 (Programming) · arithmetic, integer division, and MOD — no if statements or loops needed Name: Date: Period:
What this is. Part A you do by hand — no computer. Predict what Python would give, and watch the traps: division that turns into a decimal, the difference between / and // , and order of operations. Part B is a short program you’ll write and run.
A1 · Division and remainder Write the exact value Python would give. Careful: some of these are decimals.
A2 · Order of operations Same rules as math class: parentheses, then ** , then * / // % , then + -.
Trap to remember. A single slash / always gives a decimal (a float ), even when it divides evenly: 8 / 2 is 4.0 , not 4. Use // when you want a whole number.
A3 · Types and conversion Answer in words where asked.
A4 · Put MOD to work
Why this matters (the reading). Every one of these shows up as a “what does this print?” question. The two rules that catch the most people: (1) / makes a float, // keeps it whole; (2) anything typed with input() is text until you convert it with int() or float().
Goal. Ask the user for a whole number of seconds, then print how many hours , minutes , and seconds that is. This is the change- maker idea with time: // pulls out the whole groups, % keeps what’s left over.
The math you need
Step Expression Why Whole hours total // 3600 3600 seconds in an hour Seconds left after hours total % 3600 the remainder Whole minutes remaining // 60 60 seconds in a minute Seconds left over remaining % 60 the final remainder
Requirements ☐ Start the file with a purpose sentence comment: # This program ___ so that ___ ☐ Use input() to ask for the seconds, and int() to convert it to a number ☐ Use // and % to find hours, minutes, and seconds ☐ Store each result in a clearly named variable ☐ print() a clean, readable result (a sentence, not just three bare numbers) ☐ No if statements and no loops — you don’t need them