Built-in functions from the insert
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. Positions still start at 1.NUM_TO_STR(87.5)is the string"87.5". Join it with&when the line must contain words and a number.
OUTPUT LEFT("Computer", 3)
OUTPUT "Score: " & NUM_TO_STR(87.5)
Check before you convert
IS_NUM(Text)isTRUEonly when the string is a number."12a"isFALSE.STR_TO_NUM("23")is the number23, so you can add 1 to it. A string cannot be added.- Convert only after
IS_NUMsays the text is safe.
DECLARE Text : STRING
Text ← "23"
IF IS_NUM(Text) THEN
OUTPUT STR_TO_NUM(Text) + 1
ELSE
OUTPUT "bad"
ENDIF
ASC and CHR
ASC('A')is the integer code65.CHR(66)is the character'B'.- The next letter after
'A'isCHR(ASC('A') + 1).
OUTPUT CHR(ASC('A') + 1)
OUTPUT IS_NUM("12a")
Common mistakes
UCASEstill takes one character. A whole string in capitals isTO_UPPER, which you met earlier.NUM_TO_STRreturns text.STR_TO_NUMreturns a number. They are not interchangeable.
Now you try
- Use
LEFT, then a joined number, thenIS_NUMbefore a conversion.
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.
Difficulty 1/5 · 100 coins + a small bonus on first completion today
Output LEFT("Computer", 3).
Click Run to see the output here.
Difficulty 1/5 · 100 coins + a small bonus on first completion today
Output Score: 87.5 on one line by joining the word and NUM_TO_STR(87.5) with &.
Click Run to see the output here.
Difficulty 1/5 · 100 coins + a small bonus on first completion today
Text is "23". If IS_NUM(Text), output STR_TO_NUM(Text) + 1. Otherwise output bad.
Click Run to see the output here.
Difficulty 3/5 · 200 coins + a small bonus on first completion today
Read a string containing a numeric value or invalid text. If IS_NUM is true, output twice its numeric value; otherwise output invalid.
Click Run to see the output here.