Built-in functions from the insert
이 페이지는 최신 브라우저(SharedArrayBuffer 지원)가 필요합니다. Chrome, Edge, Firefox 또는 Safari를 최신 버전으로 업데이트해 주세요.
English
A receipt joins a number to text
- Every Paper 2 has an insert of built-in functions. Anything not in the pseudocode guide is printed there, and an answer may call it.
LEFT(Text, N)copies the firstNcharacters andRIGHT(Text, N)the lastN.MID(Text, Start, N)copiesNcharacters from positionStart. Positions start at 1.NUM_TO_STR(4.5)is the string"4.5". Join it to words with&:&joins strings only.

English
DECLARE Code : STRING
DECLARE Price : REAL
Code ← "LON-2026-B"
OUTPUT "City: " & LEFT(Code, 3)
OUTPUT "Year: " & MID(Code, 5, 4)
OUTPUT "Gate: " & RIGHT(Code, 1)
Price ← 3 * 1.5
OUTPUT "Total: " & NUM_TO_STR(Price)
"Total: " & Priceis wrong:Priceis aREAL, so turn it into text withNUM_TO_STRfirst.
English
Check before you convert
- Text typed by a user, or read from a file, is a
STRING, even when it looks like a number. IS_NUM(Text)isTRUEonly when the whole string is a number:"12a"and""giveFALSE.STR_TO_NUM(Text)turns the string into a number you can calculate with. Call it only afterIS_NUMsays the text is safe.
Text |
IS_NUM(Text) |
STR_TO_NUM(Text) |
|---|---|---|
"42" |
TRUE |
42 |
"3.5" |
TRUE |
3.5 |
"12a" |
FALSE |
do not call it |

English
DECLARE Entry : STRING
DECLARE Index : INTEGER
DECLARE Total : REAL
DECLARE Entries : ARRAY[1:4] OF STRING
Entries[1] ← "12"
Entries[2] ← "seven"
Entries[3] ← "30"
Entries[4] ← "4.5"
Total ← 0
FOR Index ← 1 TO 4
Entry ← Entries[Index]
IF IS_NUM(Entry) THEN
Total ← Total + STR_TO_NUM(Entry)
ELSE
OUTPUT "Skipped: " & Entry
ENDIF
NEXT Index
OUTPUT "Total: " & NUM_TO_STR(Total)
English
ASC and CHR
ASC('A')is the integer code65;'B'is66, and so on.CHR(72)is the character'H'.- Adding to a code moves along the alphabet:
CHR(ASC('C') + 2)is'E'.
English
DECLARE Letter : CHAR
Letter ← 'C'
OUTPUT ASC(Letter)
OUTPUT CHR(ASC(Letter) + 2)
OUTPUT CHR(ASC('a') - 32)
- Lower-case codes are 32 more than upper-case ones (
'a'is 97), so- 32gives the capital.TO_UPPERfrom the insert does this for you.
English
Common mistakes
| Wrong | Right | Why |
|---|---|---|
"Score: " & 87.5 |
"Score: " & NUM_TO_STR(87.5) |
& joins strings only |
STR_TO_NUM(Text) with no check |
IF IS_NUM(Text) THEN … first |
text such as "12a" is not a number |
UCASE("hello") |
TO_UPPER("hello") |
UCASE takes one character |
LEFT(Code, 0) for the first letter |
LEFT(Code, 1) |
the second value is how many characters |
MID(Code, 0, 3) |
MID(Code, 1, 3) |
positions start at 1 |
English
Now you try
- The tasks use
"Computer",87.5and"23". Choose the function, then check that the output has exactly the words and number asked for.
English
Independent transfer
The final task has no supplied algorithm. Plan its inputs, processing and outputs, then solve it before opening support. Check more than the sample case.
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
출력 LEFT("Computer", 3).
출력을 보려면 '실행'을 클릭하세요.
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
출력 Score: 87.5 on one line by joining the word and NUM_TO_STR(87.5) with &.
출력을 보려면 '실행'을 클릭하세요.
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
Text is "23". If IS_NUM(Text), output STR_TO_NUM(Text) + 1. Otherwise output bad.
출력을 보려면 '실행'을 클릭하세요.
난이도 3/5 · 200코인 + 오늘 첫 완료 시 작은 보너스 추가
Read a string containing a numeric value or invalid text. If IS_NUM is true, output twice its numeric value; otherwise output invalid.
출력을 보려면 '실행'을 클릭하세요.