← 返回资讯屏轩教育 · 行业资讯

Case Study Practical Exercises in Computing | 计算机案例分析实战演练

2026-07-16 12:30 · 本文部分内容由AI辅助创作

📚 Case Study Practical Exercises in Computing | 计算机案例分析实战演练

Case studies help students apply their computing knowledge to real-world scenarios. In this practical exercise, we will work through a complete project step by step: creating a score tracker for a classroom quiz game. You will learn how to analyse a problem, design an algorithm, write pseudocode, draw flowcharts, test your solution, and even implement it in a simple programming environment. By the end, you will have a clear method for tackling any small computing project.

案例分析能帮助学生将计算机知识运用到真实场景中。在这个实战演练中,我们将逐步完成一个完整的项目:为课堂问答游戏制作一个分数追踪器。你将学会如何分析问题、设计算法、编写伪代码、绘制流程图、测试解决方案,甚至在一个简单的编程环境中实现它。最终,你将掌握处理任何小型计算项目的方法。

1. Understanding the Problem | 理解问题

The teacher wants a simple program to keep track of scores during a quiz. Two teams compete, and each correct answer earns 10 points. The program should display the current score after each question and announce the winner at the end when the teacher enters 'done'. Read the description carefully and pick out what the program must do.

老师想要一个简单的程序来记录课堂测验的分数。两支队伍进行比赛,每答对一题得10分。程序应在每道题后显示当前分数,并在老师输入“done”时最终宣布胜者。仔细阅读描述,找出程序必须完成的任务。

2. Identifying Inputs and Outputs | 识别输入和输出

Inputs are what the program receives; outputs are what it shows or produces. For our score tracker, the inputs are the teacher's commands: which team scored, or 'done' to finish. Outputs are the updated scores and the final winner message.

输入是程序接收的内容;输出是程序显示或产生的内容。对于我们的分数追踪器,输入是老师的指令:哪支队伍得分,或输入“done”结束。输出是更新后的分数和最终的胜者信息。

Type / 类型Details / 详情
Input'A' (Team A scores), 'B' (Team B scores), 'done' (end quiz)
OutputCurrent scores after each input; 'Team A wins!', 'Team B wins!', or 'Draw!'

By defining inputs and outputs clearly, we avoid confusion later. All other data (like the scores themselves) will be stored inside the program and changed as it runs.

明确地定义输入和输出可以避免后续的混乱。所有其他数据(比如分数本身)将存储在程序内部,并在运行时更改。

3. Breaking Down the Task | 分解任务

Computational thinking means breaking a big problem into smaller, manageable pieces. Let's split our score tracker into steps: initialise scores to zero, ask for input, update scores if input is 'A' or 'B', show scores, and check if input is 'done'. If it is, decide the winner; otherwise, loop back.

计算思维意味着把一个大问题拆分成更小、更易于处理的部分。我们把分数追踪器分解为以下步骤:将分数初始化为零,要求输入,如果输入是“A”或“B”则更新分数,显示分数,检查输入是否为“done”。如果是,则判定胜者;否则回到循环开头。

This breakdown helps us design the algorithm accurately.

这样的分解有助于我们更准确地设计算法。

4. Designing the Algorithm | 设计算法

An algorithm is a step-by-step plan to solve a problem. Using the breakdown, we write a structured set of instructions. Here is our algorithm in plain English:

算法是解决问题的一步一步的计划。根据分解,我们写出结构化的指令集。下面是我们的算法(用简单英语描述):

1. Set Team A score to 0 and Team B score to 0
2. Get command from teacher
3. If command is 'A', add 10 to Team A score
4. If command is 'B', add 10 to Team B score
5. If command is not 'done', show scores and go back to step 2
6. If command is 'done', compare scores and display winner

This algorithm uses sequence, selection (if-statements) and iteration (a loop). These are the three building blocks of all programs.

这个算法使用了顺序、选择(if语句)和迭代(循环)——这是所有程序的三个基础构建块。

5. Representing the Algorithm with Pseudocode | 用伪代码表示算法

Pseudocode is a way of writing algorithms that looks like simplified programming code but is easy to read. Here's our algorithm as pseudocode:

伪代码是一种编写算法的方式,它看起来像简化的程序代码,但很容易阅读。以下是我们算法的伪代码:

teamA ← 0
teamB ← 0
REPEAT
  INPUT command
  IF command = 'A' THEN
    teamA ← teamA + 10
  ELSE IF command = 'B' THEN
    teamB ← teamB + 10
  ENDIF
  IF command ≠ 'done' THEN
    OUTPUT teamA, teamB
  ENDIF
UNTIL command = 'done'
IF teamA > teamB THEN
  OUTPUT "Team A wins!"
ELSE IF teamB > teamA THEN
  OUTPUT "Team B wins!"
ELSE
  OUTPUT "Draw!"
ENDIF

Pseudocode lets you plan the logic without worrying about exact programming language rules.

伪代码让你可以规划逻辑,而不必担心具体编程语言的语法规则。

6. Drawing a Flowchart | 绘制流程图

A flowchart shows the algorithm visually using symbols: ovals for start/end, parallelograms for input/output, rectangles for processes, diamonds for decisions, and arrows for flow. Here is a description of our flowchart (you can sketch it on paper):

流程图使用符号将算法可视化:椭圆形表示开始/结束,平行四边形表示输入/输出,矩形表示处理过程,菱形表示判断,箭头表示流程方向。以下是我们流程图的描述(你可以在纸上画出它):

Flowcharts help you spot mistakes in logic before coding, and they are useful to share your design with others.

流程图能在编码前帮助你发现逻辑错误,并且方便与他人分享你的设计。

7. Choosing Variables and Data Types | 选择变量和数据类型

In programming, we store data in variables. Each variable has a name and a data type. Our score tracker needs variables for the two scores (integers, whole numbers) and for the user's command (a string of text).

在编程中,我们用变量存储数据。每个变量有一个名字和一个数据类型。我们的分数追踪器需要两个分数的变量(整数,整型)和用户指令的变量(字符串)。

广告 / Sponsored

Variable NameData TypePurpose
teamAIntegerStores Team A's score
teamBIntegerStores Team B's score
commandStringReceives 'A', 'B', or 'done'

Choosing clear variable names makes your code easy to understand. For example, 'teamA' is much better than 'x'. Integer operations use simple arithmetic, while string comparison checks exactly for 'done'.

选择清晰的变量名能让代码易于理解。比如,“teamA”就比“x”好得多。整数运算使用简单的算术,而字符串比较则会精确检查是否为“done”。

8. Testing with Sample Data | 用样本数据测试

manually with sample inputs. Walk through the steps and track the values of variables. Let's test: inputs: 'A', 'B', 'A', 'done'. Expected output: scores after each input, final 'Team A wins!' because teamA=20, teamB=10.

在编程前,用样本输入手动测试你的算法。逐步执行并记录变量的值。我们来测试:输入为“A”、“B”、“A”、“done”。预期的输出是每次输入后的分数,最终显示“Team A wins!”,因为teamA=20,teamB=10。

Dry run table:

StepcommandteamAteamBOutput
1A10010, 0
2B101010, 10
3A201020, 10
4done2010Team A wins!

Testing reveals if your logic handles different paths correctly, including a draw scenario when both scores are equal. Always test edge cases: what if the user types 'a' instead of 'A'? (Our algorithm treats them differently – a future improvement.)

测试能揭示你的逻辑是否正确处理了不同路径,包括两者分数相同时的平局情境。始终要测试边界情况:如果用户输入“a”而不是“A”会怎样?(我们的算法会把它们当成不同指令——这是未来的改进点。)

9. Implementing in Scratch / Python | 在Scratch / Python中实现

Once the design is ready, coding becomes straightforward. In Scratch, you would use variables 'teamA' and 'teamB', an 'ask and wait' block for input, 'if-then-else' blocks for decisions, and a 'repeat until' loop. In Python, the code looks like this:

设计完成后,编码就变得很简单了。在Scratch中,你会使用变量“teamA”和“teamB”,用“询问并等待”积木获取输入,用“如果-那么-否则”积木做判断,以及“重复执行直到”循环。在Python中,代码看起来像这样:

teamA = 0
teamB = 0
command = ''
while command != 'done':
  command = input('Enter A, B or done: ')
  if command == 'A':
    teamA = teamA + 10
  elif command == 'B':
    teamB = teamB + 10
  if command != 'done':
    print('Team A:', teamA, 'Team B:', teamB)
if teamA > teamB:
  print('Team A wins!')
elif teamB > teamA:
  print('Team B wins!')
else:
  print('Draw!')

Notice how closely the code matches our pseudocode. Always indent correctly in Python to show which lines belong inside loops and conditions.

注意这段代码与我们的伪代码是多么接近。在Python中始终要正确缩进,以显示哪些行属于循环和条件块内部。

10. Debugging Common Errors | 调试常见错误

Mistakes happen – n ones in this project include forgetting to update a variable, using a single equals sign '=' to compare instead of '==', or writing 'done' check inside the wrong condition. For example, if you place the score output before checking for 'done', the program might show scores even after finishing.

错误在所难免——这叫做bug。本项目中的常见错误包括:忘记更新变量,比较时用单等号“=”而不是“==”,或者把“done”的检查写在了错误的条件里。例如,如果你在检查“done”之前就输出分数,程序可能会在结束后仍然显示分数。

Debugging technique: add print statements to show variable values during execution. This is called tracing. Run your code with known inputs and see if the outputs match your expected dry run.

调试技巧:在执行过程中添加打印语句来显示变量值。这叫跟踪。用已知的输入运行代码,检查输出是否与你预期的手动跟踪表格一致。

Another common pitfall: capitalisation. 'A' and 'a' are different strings. Decide whether to accept both by using .upper() or adding extra conditions.

另一个常见的陷阱:大小写。“A”和“a”是不同的字符串。你需要决定是否通过使用.upper()或添加额外条件来同时接受二者。

11. Evaluating the Solution | 评估解决方案

After coding, evaluate your solution against the original requirements. Does it update scores correctly? Does it display scores after each question? Does it end when 'done' is entered and declare the winner? Also consider usability: is the instruction clear for the teacher? Would it be helpful to show a running total message like 'Team A now has 20 points'?

编程结束后,对照原始需求评估你的解决方案。它能正确更新分数吗?每道题后能显示分数吗?输入“done”后会结束并宣告胜者吗?还要考虑可用性:给老师的指示是否清晰?如果能显示“Team A 现在有 20 分”这样的累积信息,是否会更有帮助?

You can also evaluate efficiency: the solution uses simple variables and a single loop, which is fast enough for this small task. No unnecessary steps. Good code is readable, works correctly, and is easy to modify later.

你还可以评估效率:这个方案使用了简单的变量和一个循环,对于这个小任务来说足够快速了。没有不必要的步骤。好代码应具有可读性、正确性,并且易于后续修改。

12. Extending the Project | 扩展项目

Now that you have a working score tracker, think of ways to improve it. You could add a feature to subtract points for wrong answers, or allow the teacher to set different point values per question. Maybe add a timer or keep track of how many questions were asked. For example, if input is 'W' for wrong answer, subtract 5 points from the specified team.

既然你有了一个可用的分数追踪器,想想如何改进它。你可以添加一个功能,对错误答案扣分,或者允许老师为每道题设置不同的分值。也许可以添加一个计时器,或者追踪总共出了多少题。例如,如果输入“W”表示错误回答,可以从指定队伍减去5分。

Another extension: make the program validate input so that it only accepts 'A', 'B', or 'done', and gives an error message otherwise. Or instead of typing, create a graphical interface with clickable buttons. Each extension gives you practice in thinking computationally and planning new features.

另一个扩展:让程序验证输入,只接受“A”、“B”或“done”,否则给出错误提示。或者不通过打字输入,而是创建一个带有可点击按钮的图形界面。每个扩展都能让你练习计算思维和规划新功能。

Remember, the case study approach – analyse, design, implement, test, evaluate – applies to any computing project, big or small.

请记住,这种案例分析方法——分析、设计、实现、测试、评估——适用于任何大小的计算项目。

Published by TutorHao | Computing Revision Series | aleveler.com

广告 / Sponsored
现货 Cambridge International AS & ALevel IT Coursebook剑桥国际IGC…
计算机 备考教辅 · 正版现货 · 与本文内容相关
查看详情 / View on Taobao参考价 ¥467.0

更多咨询请联系16621398022(同微信)

备考资讯每日更新,关注不错过
考纲变化 · 科目分析 · 学习方法
扫码关注公众号 tutorhao
在微信里长按二维码识别关注
或截图后用「扫一扫 → 相册」选择本图
公众号:tutorhao