Program Function and Purpose
引入本课内容
| English | 释义 | 拼音 |
|---|---|---|
| purpose/ˈpɜːpəs/ | 目的 | mù dì |
| function/ˈfʌŋkʃn/ | 功能 | gōng néng |
| behavior/bɪˈheɪvjə/ | 行为 | xíng wéi |
| Input/ˈɪnpʊt/ | 输入 | shū rù |
| Processing/ˈprəʊsesɪŋ/ | 处理 | chǔ lǐ |
| Output/ˈaʊtpʊt/ | 输出 | shū chū |
| events/ɪˈvents/ | 事件 | shì jiàn |
| event-driven/ɪˈvent ˈdrɪvən/ | 事件驱动 | shì jiàn qū dòng |
| event handler/ɪˈvent ˈhændlə/ | 事件处理程序 | shì jiàn chǔ lǐ chéng xù |
目的与功能
- 写代码之前,先弄清两个相关的想法。
- 程序的目的(purpose)是它为什么存在——它解决的问题。
- 功能(function)是它做什么——用户看到的行为。
- 一个天气应用的目的是"帮人们做计划";它的功能是"显示预报"。
Input, processing, or output?
Every program takes input, processes it by its instructions, and produces output. Sort each part of a program into the right stage.
A program's purpose is why it exists; its function is:
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
Purpose = the goal; function = the visible behavior that reaches it.
Which is an example of input?
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
A tap is data the program receives; the others are outputs.
输入 → 处理 → 输出模型
- 每个程序都遵循一个简单模型:输入 → 处理 → 输出(IPO 模型 IPO model)。
- 输入(input):程序接收的数据——打字、传感器、文件、互联网。
- 处理(processing):它对该输入执行的步骤。
- 输出(output):结果——文字、声音、保存的文件、机器人移动。

每个程序都可分解为输入、处理和输出
Put the IPO model in order.
难度 3/5 · 今日首次完成可获 200 金币及少量额外奖励
Data comes in, is processed, and a result goes out.
A program that waits and reacts to clicks and key presses is ______-driven.
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
Each event triggers an event handler.
A program always gives the same output, whatever input it receives.
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
False. A program's behavior is how it responds to input, so different inputs can give different outputs.
行为与事件
- 程序的行为(behavior)是它如何响应输入——不同的输入能给出不同的输出。
- 许多现代程序是事件驱动(event-driven)的:它们等待并响应事件(events),如点击或按键。
- 每个事件触发一小段代码,叫事件处理程序(event handler)。
- 一个游戏、一个网页按钮和一个聊天应用都是事件驱动的。
A well-designed program should: (Select all that apply)
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
Good design also handles every possible input, including unusual ones.
一个设计良好的程序做什么
- 为用户解决一个真正的问题。
- 清楚说明它期望的输入和给出的输出。
- 每次运行都可靠地完成它的工作。
- 思考每一种可能的输入是正确设计程序的一部分。
例题:计步应用
一个计步应用帮助人们保持活跃。它读取手机的运动传感器数据,记录每一步,并显示当天的总步数;当用户点击“重置”时,计数归零。指出它的目的、功能、输入、处理、输出和一个事件。
- 目的:帮助人们保持活跃。功能:计数并显示步数。输入:运动传感器数据和对屏幕的点击。
- 处理:在传感器数据中识别步行的模式,并将计数加 1。输出:屏幕上的总步数。事件:点击“重置”会触发它的事件处理程序,将计数设为 0。
In a calculator app, the user typing "7 × 6" is the:
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
It is data given to the program.
In an event-driven program, code runs in response to actions such as a click or key press.
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
Each event triggers its handler.
程序的目的是它为什么存在;它的功能是它做什么。每个程序都符合输入 → 处理 → 输出(IPO 模型)。它的行为是它如何响应输入——许多程序是事件驱动的,通过事件处理程序响应点击和按键。
出了什么问题?只有网站团队能看到这些信息。