UCASE and LCASE functions

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

UCASE and LCASE functions

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What does UCASE("Happy") return?
A "HAPPY"
B "happy"
2. What does LCASE('W') return?
A 'w'
B 'W'
3. Which function changes the text "cat" into "CAT"?
A LCASE("cat")
B UCASE("cat")
4. Which line of Cambridge pseudocode is written correctly?
A Answer ← lcase(Reply)
B Answer ← LCASE(Reply)
5. A program asks 'Do you want to play again? (Y/N)'. The user types y. Which condition still matches 'Y'?
A UCASE(Reply) = 'Y'
B Reply = 'Y'

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1UCASE("Happy") AUCASE makes Answer all capitals, so it can never equal the lower case text "yes". The comparison is always false. It should be "YES".
2LCASE('W') BReturns the character 'w' in lower case
3Make sure an answer typed as "yes", "Yes" or "YES" is treated the same by converting it to upper case before comparing CThe argument must be inside brackets after the function name. It should be LCASE('K').
4Store a copy of the user's name in lower case so that it can be compared without worrying about capital letters DIF UCASE(Answer) = "YES" THEN
5IF UCASE(Answer) = "yes" THEN ELowerName ← LCASE(Name)
6Letter ← LCASE 'K' FReturns the string "HAPPY" with every letter in upper case

Definitions

UCASE(x) and LCASE(x)

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
OUTPUT _____("Happy")
2.
OUTPUT _____('W')
3.
INPUT Answer Shout ← UCASE(______) OUTPUT Shout
4.
INPUT Answer Match ← UCASE(Answer) _ "YES" OUTPUT Match
5.
DECLARE Letter : CHAR Letter ← LCASE('W') OUTPUT ______

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A Word ← "Happy"
B Word ← 'Happy'
C OUTPUT Shout
Question 2
A INPUT Answer
B Answer ← UCASE(Answer)
C Answer ← LCASE(Answer)
D OUTPUT "Accepted"
E ENDIF
Question 3
A Letter ← LCASE 'W'
B OUTPUT Letter
C // Letter is now 'w'
Question 4
A INPUT Code
B Code ← UPPER(Code)
C OUTPUT "Code: ", Code
Question 5
A DECLARE Name : STRING
B Name ← "Zoe"
C OUTPUT UCASE("Name")

Answer Key

UCASE and LCASE functions
Section A: Quick Questions
Q1
A — "HAPPY"
Q2
A — 'w'
Q3
B — UCASE("cat")
Q4
B — Answer ← LCASE(Reply)
Q5
A — UCASE(Reply) = 'Y'
Section B: Match the Pairs
Q1
UCASE("Happy") → Returns the string "HAPPY" with every letter in upper case
Q2
LCASE('W') → Returns the character 'w' in lower case
Q3
Make sure an answer typed as "yes", "Yes" or "YES" is treated the same by converting it to upper case before comparing → IF UCASE(Answer) = "YES" THEN
Q4
Store a copy of the user's name in lower case so that it can be compared without worrying about capital letters → LowerName ← LCASE(Name)
Q5
IF UCASE(Answer) = "yes" THEN → UCASE makes Answer all capitals, so it can never equal the lower case text "yes". The comparison is always false. It should be "YES".
Q6
Letter ← LCASE 'K' → The argument must be inside brackets after the function name. It should be LCASE('K').
Section C: Definitions
Q1
UCASE(x) and LCASE(x) — UCASE returns a string or character in upper case, e.g. UCASE("Happy") gives "HAPPY". LCASE returns it in lower case, e.g. LCASE('W') gives 'w'.
Section D: Fill in the Blanks
Q1
OUTPUT UCASE("Happy")
Q2
OUTPUT LCASE('W')
Q3
INPUT Answer Shout ← UCASE(Answer) OUTPUT Shout
Q4
INPUT Answer Match ← UCASE(Answer) = "YES" OUTPUT Match
Q5
DECLARE Letter : CHAR Letter ← LCASE('W') OUTPUT Letter
Section E: Spot the Error
Q1
B — A string of several characters must be written in double quotes. Single quotes are only for a single CHAR. It should be Word ← "Happy".
Q2
C — LCASE makes the answer lower case, so it can never equal "YES". To compare with "YES" the answer must be converted with UCASE(Answer).
Q3
A — A function call needs brackets around its argument. It should be Letter ← LCASE('W').
Q4
B — UPPER is not a Cambridge pseudocode function. The function that returns upper case is UCASE, so it should be Code ← UCASE(Code).
Q5
C — Putting Name in quotes passes the text "Name" to UCASE, so it would output NAME. To output ZOE, pass the variable: OUTPUT UCASE(Name).