AQA GCSE Computer Science sample Paper 1, Question 8: is it lowercase?

AQA 8525 sample assessment material, Paper 1 Question 8: write a Python program that inputs a character and outputs LOWER or NOT LOWER. Two ways to test for lowercase, the seven marks, the AND OR trap, and the program to run.

Past paper questionAQA 8525/1BSample Paper 17 marksWrite a program

Question 8 of AQA's sample assessment material for GCSE Computer Science Paper 1 (8525/1B, the Python paper) is 7 marks for a four line program. The whole question is one condition: is a character a lowercase letter?

We do not copy the paper here. Open it beside this page: AQA 8525 Paper 1B sample question paper (PDF). When you have finished, check the sample mark scheme too.

The question in short

Get the user to enter a character. Output LOWER if it is a lowercase letter, and NOT LOWER for anything else.

Two ways to test it

Python strings compare alphabetically, and all the lowercase letters sit between 'a' and 'z':

character = input("Enter a character: ")
if character >= "a" and character <= "z":
    print("LOWER")
else:
    print("NOT LOWER")

Or use the string method that does the job:

if character.islower():

Both get full marks.

Where the seven marks are

Three for design: the idea of inputting a character and testing it; selection; meaningful variable names. Four for a program that works: the input; stored in a variable; a correct lowercase test; LOWER and NOT LOWER in the two branches.

Where the marks are lost

  • or between the comparisons. character > "a" or character < "z" is true for everything: every character is either after a or before z. The mark scheme shows exactly this as its 5 mark example.
  • > and <. a and z are lowercase. The range is inclusive: >= and <=.
  • character == "a" or "b" or .... Writing out the alphabet is slow and the or chain does not work.
  • Comparing with the number of the character. ord(character) between 97 and 122 works too, but the letters are easier to get right.

Run it

Type a character. The robot's light is green for lowercase.

Try g (LOWER), G (NOT LOWER), 7 (NOT LOWER) and a (LOWER: the boundary).
The program
from bugbot import *
connect()

character = input("Enter a character: ")
if character >= "a" and character <= "z":
    led("green")
    print("LOWER")
else:
    led("red")
    print("NOT LOWER")
Put this demo on your own site

Paste it into a school website, Moodle, Google Sites or a blog. More options on the embed page.

Questions

What is the answer to AQA sample Paper 1 Question 8?

Input a character. If it is greater than or equal to "a" and less than or equal to "z", print LOWER, otherwise print NOT LOWER. character.islower() is accepted instead of the comparison.

How do I check whether a character is a lowercase letter in Python?

Either compare it with "a" and "z" using and, or call the string method islower(), which returns True for a lowercase letter.

Why does "b" >= "a" work in Python?

Strings are compared by the codes of their characters, and the lowercase letters have consecutive codes from 97 for a to 122 for z. So the comparisons follow the alphabet.

More from this paper

Every AQA 8525 question we have worked

Learn it step by step

  1. F3.1 String handling Strings, lists and records
  2. F2.2 Selection: if Decisions and loops
  3. F3.2 Character codes and conversion Strings, lists and records
Open the lessons

This is our own explanation of a published exam question. It is not written or endorsed by AQA, and the question paper and mark scheme remain AQA's copyright. Read them on AQA's site with the links on this page.