# That Blue Square Thing

## AQA Computer Science GCSE

September 2020: This page is the for the 2022 exam version of the AQA Computer Science GCSE course. This is for Year 10 teaching in September 2020.
These pages were copied over from the old syllabus and will get updated as I work through the new one. That means they won't always be totally up to date and I might miss something - check the updated date at the bottom of the page.

### Programming Concepts - Input Statements

Input statements allow users to enter data to be used in a program.

This is a really fundamental area of coding. Without the ability to enter values programs aren't very flexible. It's crucial that you understand input statements and how they work.

One key idea is that you want to "capture" the values being entered. This means that you need to assign them to a variable.

The pseudocode to allow user input is straightforward.

catName <- USERINPUT

If you need to output a message with the input line you need to do that using an OUTPUT statement on a separate line:

OUTPUT "Enter the cat's colour:"
catColour <- USERINPUT

In Python the message and input can be combined on the same line.

print() # print a blank line
print("Name: " + yourName) # one way of printing on one line
print("Age", yourAge) # another way of printing on one line

The key thing to remember is to always assign an input value to a variable.

### Inputting numbers

Inputting numbers is slightly more complex.

Python always assumes that anything inputted using an input statement will be a string - i.e. a word (see more about data types). This includes what you might think of as a number. Python sees "42" and things it's a word made up of the character '4' and the character '2'. It absolutely doesn't think of it as a number.

This means you can't do things like this:

# this code won't work!

yourAge = yourAge + 10 # add 10 years to yourAge
print(yourAge)

To solve this problem we have to tell Python that we want to consider the input as a number. We can do this by converting the input to a number - often to an integer (a whole number).

Here's how to do that:

# this code will work!
yourAge = int(yourAge) # convert to an integer

yourAge = yourAge + 10 # add 10 years to yourAge
print(yourAge)

Sometimes you want to use a decimal number rather than an integer. Now you have to convert to a floating point number (a float data type).

print(yourShoeSize)

Note that this time I converted at the same time as the input happened. This is fine to do with integers as well - but take care to include the right number of closing brackets (I reliably miss one off and end up with a syntax error on the next line down).

### Printing Numbers

It's all very well converting inputs to numbers, but you need to be a little careful when you print them out again.

Python can cope with a simple print statement with a number in it, like this:

print(yourAge)

But if you want to print the number out on the same line as words you need to be careful how you do it. Take a look at the code below to see.