# That Blue Square Thing

This page includes . Mouse over them to get a brief explanation of what something means.
Tootips might not work so well on phones or tablets. Sorry.

## AQA Computer Science GCSE

This page is up to date for the new AQA 8525 syllabus for the 2022 exam. Make sure you check the revision pages to see which topics will be on the 2022 exam.

### Programming Exam Question - Taxi firm

This is a four mark paper 1 programming question. It was question 15 on the specimen exam paper and starts by giving you some Python code to work from.

I suggest trying to write an answer by hand first and then attempting to program your answer. Does it work? What did you get wrong?

#### The Question:

A program has been written in Python to display all the odd between 1 and the largest odd number smaller than an integer entered by the user. The program is shown in Figure 6.

Figure 6

odd = 1
number = int(input("Enter an integer: "))
while odd != number:
print(odd)
odd = odd + 2
print("Finished!")

The program works correctly if the integer entered by the user is an odd, positive integer. For example, if 7 is entered the program correctly displays the values 1, 3 and 5

The program does not work correctly if an odd integer less than 1 is entered by the user. For example, when -7 is entered the program should display the values 1, -1, -3 and -5 but does not do this.

Using Python only, change the program code inside the while loop so that it will work correctly for any odd integer entered by the user.

[4 marks]

#### Hints

You can uncover a set of hints below.

With a pencil and some paper. Really: try and do this by hand first. That way when you try it in Python the syntax errors will get picked up and you'll learn from your mistakes. Lots of people find writing code by hand difficult. The only way to learn is to do it.
This is all about changing the code inside the while loop to deal with negative numbers. Some things to note:
• you'll need to deal with negative numbers differently (but not that much differently) from how the program already deals with even numbers
• part of this will involve using selection - if you construct this properly you'll get a mark even if your logic is wrong
• there's no need to include any of the code from Figure 6 other than the stuff inside the while loop - you don't even need to write out the while... line
This is quite hard to figure the idea out for, so I will probably get around to putting up a solution and a markgrid at some point. Some people might know where the markschemes are anyway. That's fine - but I'd try and do the task first
You don't need it. Just use a piece of paper and make sure your indents are clear

Note that the second line of code in this question is pretty much exactly the code you'd need to ge a user input for questions 5 and 18 and very similar to what you'd need in questions 6 and 8. This line, with it's variations, is one you need to just remember.

#### Suggested Test Data:

The question gives you the two tests to use:

 Test type Test data Expected result Normal data 7 1, 3, 5, Finished! - it's important to test this as you'll have changed the program and if this doesn't work as expected then you've done something wrong! Normal data -7 1, -1, -3, -5, Finished! - this is given in the question Boundary data 1 Finished! This is an interesting test. I don't think the question, as written, should output any numbers - there are no numbers between 1 and 1. Certainly, the code won't output anything and the question states that it works correctly for any odd, positive integer, so I think we should assume that this is the intention.

Note that you don't need to consider even numbers. The question is very specific: you can assume that an odd integer is entered.