Practice Questions · AP CSP-Feeder · US / ON / BC / AB Styles练习题集 · AP CSP 衔接 · 美 / 安 / 卑 / 阿省风格
Questions mix multiple-choice and short-answer items. For MCQs, circle the letter and show your reasoning in the work space. For short-answer items, state the exact value or type (e.g., "a string, '55'"). Code is pseudocode or Python; trace each step to verify before answering.本部分包含选择题与短答题。选择题请圈出字母,并在答题空白处写出推理过程。短答题写出精确值或类型(如"字符串 '55'")。代码为伪代码或 Python;作答前逐步追踪。
After the following three lines execute, what is the value of y?以下三行执行后,y 的值是什么?
x = 4
y = x + 3
x = 10
101374Which of the following is the correct data type for the value "3.14" (with quotes) in Python?以下哪项是 Python 中 "3.14"(带引号)的正确数据类型?
A student writes the following program. The user types 5 at the prompt.一名学生编写了以下程序。用户在提示符处输入 5。
n = input("Enter a number: ")
result = n * 2
print(result)
n after line 1 executes. Explain why.写出第 1 行执行后 n 的数据类型。解释原因。 [2]result holds after line 2 executes. State its data type too.写出第 2 行执行后 result 保存的精确值。同时写出其数据类型。 [2]result to be 10 (integer). Write the corrected line 1 that fixes the bug.学生希望 result 为 10(整数)。写出修正后的第 1 行以修复该错误。 [2]Given a = 17 and b = 5, evaluate each expression below.给定 a = 17,b = 5,计算以下每个表达式。
a // b and its data type.写出 a // b 的值及其数据类型。 [2]a % b and explain what it represents.写出 a % b 的值,并解释它代表什么。 [2]a > 10 and b == 5 and state whether the result is True or False. Show your reasoning.计算表达式 a > 10 and b == 5,写出结果是 True 还是 False。写出推理过程。 [2]For each line of Python below, state the result and its data type. If the line raises an error, name the error.对以下每行 Python,写出结果及其数据类型。若该行引发错误,请说明错误名称。
int(7.9) [2]str(42) + " points" [2]int("3.9") [2]Show every step of your trace. Write pseudocode or Python clearly, with correct indentation. For justify questions, two sentences of reasoning earn full marks. State data types whenever asked. Calculator not applicable; trace by hand.写出每一步追踪过程。伪代码或 Python 须清晰书写,缩进正确。论证题两句推理即可满分。有要求时须写明数据类型。无需计算器;手工追踪。
Answer each naming question below.回答以下每道命名问题。
snake_case convention for a variable storing a student's total score?哪个变量名遵循 Python 的 snake_case 规范,用于存储学生的总分? [1]
TotalScoretotal_scoreTOTAL_SCOREts0.13 should not change during the program. Write the correctly named Python line that declares it as a constant.税率值 0.13 在程序运行中不应改变。写出将其声明为常量的正确命名 Python 语句。 [1]TAX_RATE = 0.13 instead of the literal 0.13 throughout the code is better practice.用两句话解释为什么在代码中使用 TAX_RATE = 0.13 而不是字面值 0.13 是更好的实践。 [2]A student writes a program to swap two variables and then print the result. Assume the user types 10 for the first prompt and 20 for the second.一名学生编写程序来交换两个变量并打印结果。假设用户第一个提示符输入 10,第二个输入 20。
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
temp = a
a = b
b = temp
print(a, b)
a, b, and temp after that line executes.逐行追踪程序。对第 3-5 行,写出该行执行后 a、b、temp 的值。 [3]temp variable is required for the swap. What would happen if you wrote a = b followed directly by b = a without using temp?解释为什么交换时需要 temp 变量。若直接写 a = b 然后 b = a 而不使用 temp,会发生什么? [2]Each buggy program below contains one or more errors. Identify the error(s) and write the corrected code.以下每个有问题的程序包含一个或多个错误。识别错误,并写出更正后的代码。
Program A:程序 A:
score = input("Enter score: ")
bonus = score + 10
print("Final score:", bonus)
Program B:程序 B:
price = float(input("Enter price: "))
message = "Total is " + price
print(message)
Final score: 95 when the user enters 85.写出更正后的程序 A。当用户输入 85 时,更正版应输出 Final score: 95。 [2]str() concatenation or an f-string.写出更正后的程序 B 中构建消息字符串的那一行。可以使用 str() 拼接或 f 字符串。 [2]A student must write a program that reads a weight in kilograms and a height in metres from the user, computes the Body Mass Index (BMI = weight / height squared), and prints the BMI rounded to one decimal place.一名学生须编写一个程序:从用户读取体重(千克)和身高(米),计算体重指数(BMI = 体重 / 身高平方),并打印保留一位小数的 BMI。
float(input(...)) for reading inputs and an f-string with :.1f for the output.用五步流程编写完整 Python 程序。使用 float(input(...)) 读取输入,用带 :.1f 的 f 字符串输出。 [3]weight = 70 and height = 1.75. Show the calculation and state the printed output.用 weight = 70、height = 1.75 追踪你的程序。写出计算过程,并写出打印的输出。 [2]Read each scenario carefully before writing code or traces. Where pseudocode is requested, use the standard block format (INPUT, SET, OUTPUT). Where Python is requested, show indentation correctly. Conclude each question with a one-sentence answer.动笔前仔细阅读每个场景。伪代码使用标准格式(INPUT、SET、OUTPUT)。Python 须正确缩进。每题以一句完整的结论句作答。
A program reads the number of minutes a student studied and converts it to hours and leftover minutes. For example, 200 minutes = 3 hours and 20 minutes.一个程序读取学生学习的分钟数,并将其转换为小时数和剩余分钟数。例如,200 分钟 = 3 小时 20 分钟。
minutes = int(input("Enter total minutes studied: "))
hours = minutes // 60
leftover = minutes % 60
print(hours, "hours and", leftover, "minutes")
data. Record whether x % 2 == 0 is True and the running values of count and total.对 data 的每个元素追踪程序,记录 x % 2 == 0 是否为 True,以及 count 和 total 的累计值。 [4]200. State the values of hours and leftover after lines 2 and 3 execute. Show your arithmetic.用输入 200 追踪程序。写出第 2、3 行执行后 hours 和 leftover 的值。写出算术过程。 [3]200.写出输入为 200 时程序的精确输出。 [1]int() conversion on line 1 necessary? What error would occur without it when the user types 200?为什么第 1 行的 int() 转换是必要的?若没有它,用户输入 200 时会发生什么错误? [2]A student is writing a program to compute an HST-inclusive price. Ontario HST rate is 13%. The program should read a pre-tax price, compute the tax, and display the final price with two decimal places. The student's first draft is shown below.一名学生正在编写一个程序,计算含 HST 的价格。安大略省 HST 税率为 13%。程序应读取含税前价格,计算税额,并以两位小数显示最终价格。学生的初稿如下。
# Draft 1
p = input("Enter price: ")
t = p * 0.13
f = p + t
print("Final:", f)
:.2f for the output line. The corrected version should handle decimal inputs correctly.用描述性名称和税率具名常量重写程序。输出行使用带 :.2f 的 f 字符串。更正版应正确处理小数输入。 [4]100.00. State the values of each variable and the printed output.用输入 100.00 追踪你的更正程序。写出每个变量的值以及打印的输出。 [2]A student is writing a program that asks the user for their first name and birth year, then prints a personalised message with their age. Today's year is 2026. The student's buggy version is shown below.一名学生正在编写一个程序,询问用户的名字和出生年份,然后打印带有年龄的个性化消息。今年是 2026 年。学生的有错误版本如下。
CURRENT_YEAR = 2026
name = input("Enter your first name: ")
birth_year = input("Enter your birth year: ")
age = CURRENT_YEAR - birth_year
message = "Hello " + name + "! You are " + age + " years old."
print(message)
"Li" and birth year 2010. State the exact printed output.用名字 "Li"、出生年份 2010 追踪你的更正程序。写出精确的打印输出。 [2]AAP-1.A · AAP-1.B · AP CSP 2.1ICS3U A1.1 · A1.3 · A1.4 · A2.1Full Syllabus Map in Study Guide: ../Study Guides/Unit_2_Programming_Fundamentals.html. CS has no AB standalone diploma exam; AB framing uses CSE1110 outcomes.完整大纲对照见学习指南:../Study Guides/Unit_2_Programming_Fundamentals.html。CS 无独立 AB 毕业考;AB 题使用 CSE1110 结果框架。