Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Follow the string routines.
DECLARE Word : STRING
Word ← "Computer"
OUTPUT LENGTH(Word)
OUTPUT SUBSTRING(Word, 4, 3)
OUTPUT LCASE(SUBSTRING(Word, 1, 1)), UCASE(SUBSTRING(Word, 2, 3))Write down the three lines of output.
DIV is the whole part of a division and MOD the remainder. ROUND(Value, Places) rounds to a number of decimal places, and RANDOM() returns a number from 0 to 1. LENGTH(Text) counts the characters, SUBSTRING(Text, Start, Length) takes a piece starting at Start (position 1 is the first character), UCASE and LCASE change the case.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Line 1. LENGTH("Computer") is 8.
Line 2. Positions 4, 5 and 6 hold p, u and t, so the output is put.
Line 3. SUBSTRING(Word, 1, 1) is C, and LCASE makes it c. SUBSTRING(Word, 2, 3) is omp, and UCASE makes it OMP. OUTPUT shows the two side by side: cOMP.
Answer: 8, put and cOMP.
Check. In Python the same pieces are word[3:6] and word[1:4], because Python counts from 0.
Log in to join the discussion.
Loading…