Practice Test 7 - AP Computer Science Principles
20 questions. Answer them in any order, then submit to see your score and every explanation.
- A weather program calculates the average temperature for a month. Input: tempsList of daily readings, where some entries may be missing (null). Output: average of available readings. Constraints: list length is 28–31, and missing values should not count. Based on the described problem, which part of the algorithm handles input constraints?
- A marketing company legally obtains data about a user's geolocation from a mapping app, their purchase history from an e-commerce site, and their stated interests from a social media profile. What is the primary privacy risk of combining these disparate data sets?
- A program simulates daily weather for a class project using random values for temperature and precipitation. Temperatures range from 40°F to 95°F, and precipitation can be none, rain, or snow. Randomness models real-world uncertainty, since weather changes without a fixed pattern. Some weeks become mostly sunny, while others include several rainy days. Based on the scenario above, how do random values affect the outcome of this weather simulation?
- Based on the code snippet for student grading: IF score > 90 grade="A" ELSE IF score >= 80 grade="B" ELSE grade="C". What is the output when score is 90?
- What will be the output of the following code segment when age is 16? IF(age >= 18) { DISPLAY("Adult") } ELSE { DISPLAY("Minor") }
- A to-do list of strings starts as ['Pack','Print tickets','Charge phone','Lock door','Leave']. You try to mark the second task done with tasks[5] = 'DONE', but the list has only five items. In the context of the problem, identify the error in the list operation and suggest a correction.
- Which of the following scenarios best demonstrates the concept of network routing?
- A student is writing a program that simply adds two user-provided numbers and displays the result. The student considers importing a large, advanced scientific computing library that contains thousands of procedures. Which of the following is the most appropriate evaluation of this choice?
- Read the passage. In a streaming service, compression shrinks data so videos load quickly and use less bandwidth. The text explains that lossless compression preserves every bit of information, while lossy compression removes some details to achieve smaller files. For digital media, JPEG commonly compresses photos by discarding subtle image data, and MPEG commonly compresses video by reducing repeated or less-noticeable visual information across frames. This creates a trade-off: smaller files and smoother streaming versus potential blur or blocky artifacts. In contrast, text and program files often use lossless methods such as Huffman coding and LZW, since even a missing character can change meaning. Based on the text, why is lossy compression preferred in streaming video?
- A student analyzes thousands of records with Pandas (a library) after
df = pd.read_csv("sales.csv"). They need total revenue per store usingdf.groupby("store")["revenue"].sum(). Using the library mentioned, how doesgroupbyimprove efficiency? - A system that includes redundant components is designed to improve its fault tolerance. The inclusion of these extra components directly supports which goal?
- What is the primary difference between using individual variables versus using a list to store related data?
- An access control system unlocks a server room when if (hasBadge AND NOT isOnDenyList) is true; otherwise it sounds a buzzer. Based on the algorithm described, what is the result of the boolean expression when hasBadge is true and isOnDenyList is true?
- An email client offers the user a choice when attaching a photo: send as 'Actual Size' or 'Small'. The 'Small' option results in a much faster email delivery. This functionality is most likely implemented using which of the following techniques?
- Given this shopping-cart pseudo-code, what will the discount be if isMember=true, total=90, isSeasonSale=true? // Inputs: isMember, total, isSeasonSale IF isMember IF total >= 100 IF isSeasonSale discount = 0.20 ELSE discount = 0.10 ELSE discount = 0.05 ELSE IF isSeasonSale AND total >= 150 discount = 0.15 ELSE discount = 0.00
- Which of the following statements best describes an advantage of the procedure call used in Program B compared to the code in Program A?
- A transportation agency uses a traffic flow simulation to test a new bus-only lane downtown. The real-world problem is predicting whether reallocating one lane improves total travel time or just shifts congestion. The simulation represents vehicles as agents that follow basic rules: maintain safe distance, accelerate when space opens, and stop at red lights. Variables include vehicleDensity (15–90 vehicles/km/lane), lightCycleTime (50–150 seconds), and peakHourFactor (1.0–3.0) that increases arrivals near 8 a.m. The algorithm iterates each second: it spawns vehicles based on peakHourFactor, updates positions and speeds, and records queue lengths at intersections. After a full simulated hour, it computes average delay per vehicle. To refine results, it repeats the hour-long simulation across many random arrival patterns, then modifies lightCycleTime to reduce the worst delays while keeping cross-street waits within a fairness limit. Scenario-specific example: at very high vehicleDensity, even a well-tuned lightCycleTime may not prevent gridlock if too many vehicles enter the network.
- A smart watch records a user's heart rate every minute as a number. A companion smartphone app translates this raw data into a graph showing heart rate over time and also transforms it into daily summaries like 'average resting heart rate'. How does this process help the user gain knowledge?
- The rise of modern crowdsourcing is most directly facilitated by which technological trend?
- Based on the code snippet for student grading: IF score >= 90 grade="A" ELSE IF score >= 80 grade="B" ELSE grade="C". What is the output when score is 89?