Operators, strings and subroutines
導入済み
13:08
プログラミング
Here is a short program. It reads five test marks and prints the total. The five marks are eight, nine, seven, six and ten, so the total should be forty. Watch…
英語のナレーション・英語と中国語の字幕を切り替え可能
このレッスンの内容
| English | 意味 |
|---|---|
| program/ˈprəʊɡræm/ | A set of instructions specifying operations for a computer to carry out. |
| values/ˈvæljuːz/ | |
| operators/ˈɒpəreɪtəz/ | 演算子 |
| strings/strɪŋz/ | LENGTH, SUBSTRING , UCASE, LCASE. |
| code/kəʊd/ | |
| comments/ˈkɒments/ | Explanatory text in source code or markup that does not execute as a program instruction. |
| Arithmetic/əˈrɪθmətɪk/ | |
| power/ˈpaʊə/ | |
| library routines/ˈlaɪbrəri ruːˈtiːnz/ | Reusable functions or procedures supplied in a collection for programs to call. |
| remainder/rɪˈmeɪndə/ | For integer division here, the amount left after taking whole groups of the divisor. |
| Relational/rɪˈleɪʃənl/ | |
| Boolean/ˈbuːlɪən/ | A logical value that is either true or false. |
| Logical/ˈlɒdʒɪkl/ | |
| characters/ˈkærɪktəz/ | A text unit such as a letter, digit, punctuation mark or other symbol. |
| LENGTH/leŋθ/ | |
| SUBSTRING/ˈsʌbstrɪŋ/ | |
| UCASE | |
| LCASE | |
| procedure/prəˈsiːdʒə/ | 手続き |
| function/ˈfʌŋkʃn/ | 関数 |
| RETURN/rɪˈtɜːn/ | |
| parameter/pəˈræmɪtə/ | 引数 |
| local variable/ˈləʊkl ˈveərɪəbl/ | ローカル変数 |
| subroutine/ˈsʌbruːtiːn/ | |
| global/ˈɡləʊbl/ | グローバル |
| CALL/kɔːl/ |
プログラムのツール
- プログラムは演算子を使って値を組み合わせ、文字列を扱う。
- コードの重複を防ぐため、プロシージャと関数を使う。
- 適切な名前付けとコメントにより、プログラムは保守可能になる。
演算子
- 算術演算子:
+ - * /,^(累乗),MOD(余り),DIV(整数部分)。例:17 MOD 5 = 2,17 DIV 5 = 3。 - 比較演算子(布尔値を返す):
= < <= > >= <>(不等号)。 - 論理演算子:
AND(両方が真),OR(少なくとも一方が真),NOT(逆転)。

A pre-condition (WHILE) loop tests before the body, so it may run zero times; a post-condition (REPEAT) loop tests after, so it runs at least once.

What is 17 MOD 5?
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
MOD gives the remainder: 17 ÷ 5 = 3 remainder 2.
What is 17 DIV 5?
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
DIV gives the whole-number part: 17 ÷ 5 = 3 (remainder discarded).
文字列処理
- 文字列は文字で構成されています。便利な操作:
- LENGTH (文字数)、SUBSTRING (部分文字列)、UCASE (大文字)、LCASE (小文字)。
name ← "Computer"
OUTPUT LENGTH(name) // 8
OUTPUT SUBSTRING(name, 1, 4) // "Comp"

変数は名前の付いたストレージであり、その値は変更可能です
SUBSTRING: take part of a string
The first character is at position 1. SUBSTRING(Word, Start, Length) takes Length characters beginning at Start — drag the two handles and read the call it builds.
What does LENGTH("Computer") return?
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
"Computer" has 8 characters.
Match each operator or string function to what it gives.
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
MOD/DIV split a division into remainder and quotient; LENGTH and SUBSTRING work on strings.
プロシージャ、関数および良いスタイル
- プロシージャ はタスクを実行します(
CALLで呼び出す);関数 は値を返す。 - パラメータ は渡される値である(最大3つ)。
- ローカル変数 はサブROUTINE内でのみ存在し(安全)、グローバル はどこでも参照可能である。
- ライブラリルーチン:
MOD,DIV,ROUND,RANDOM。 - 保守可能なプログラムは、意味のある名前、コメント、およびサブROUTINEを使用する。

基本データ型:整数、実数、文字、文字列、布尔値
A local variable:
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
Locals are safer because other parts of the program cannot change them by mistake.
A function returns a value (used in an expression) while a procedure just performs a task, and a local variable can only be used inside the subroutine where it is declared.
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
Functions return values; locals keep variables safe inside their own subroutine — both make code easier to maintain.
このカードは新しいため、翻訳ができるまで英語で表示されます。
Worked example: minutes to hours
A film lasts 135 minutes. Use DIV and MOD to calculate its length in hours and minutes, then write a function that returns 返回 the whole number of hours.
DIV(135, 60)= 2 (the whole number of hours) andMOD(135, 60)= 15 (the remainder), so the film is 2 hours 15 minutes.- As a function with a parameter, it returns a value to the program that called 调用 it:
FUNCTION Hours(Mins : INTEGER) RETURNS INTEGER
RETURN DIV(Mins, 60)
ENDFUNCTION

What is 23 MOD 4?
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
23 = 5 × 4 + 3, so the remainder is 3.
Name ← "Shanghai". What does SUBSTRING(Name, 1, 5) return?
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
It takes 5 characters starting at position 1.
理解できましたか
MOD= 余り、DIV= 整数部分;論理AND/OR/NOT- 文字列: LENGTH, SUBSTRING, UCASE, LCASE
- プロシージャ はタスクを実行;関数 は値を返す;パラメータ は値を渡す
- ローカル 変数は グローバル より安全;保守可能=意味のある名前+コメント+サブROUTINE
何が問題でしたか?この内容はサイトの運営チームだけが確認します。