# A-level Computing/AQA/Paper 1/Fundamentals of programming/Input and output

An important part of computer code is allowing your user to input data into the program, things such as text, key presses or even a data feed from a motion sensor games controller.
Once the data is in the program you want the system to output responses, these may take the form of output to a screen: graphics, text, output to a sound device, printed documents or data output to another program.
For this unit you need to be familiar with a few input and output commands. The little black box that appears on your screen is called the console. In VB.NET all the commands to read and write from this are accessed from the console. command, let's take a look at some:

## Outputs

For the AS course it is unlikely you will need anything beyond the print to screen command and the write to file command (see later). In VB.NET there are two write to screen commands that you should be familiar with:
Let's see an example of this in action:
This would output the following:
Hello how are you? I'm fine thank you.
Notice the difference between a writeline and a write command.
Python does not have two separate commands in the way VB.NET does. The print command will by default add a new line on to the end of each string. Here's an example:
will produce the output:
This is the first line. This is the second half of the first line. This is the second line.
If you want to output several things all on the same line you have to add end="" to the print command. This tells Python that instead of ending with a new line you instead want to end with nothing. So the following example outputs all on the same line:
This output will all appear on the same line.
* Extension: Console methods in VB.NET
* We can do a lot of things with the console command. If you are using Visual Studio then type the following:
* console.
* Up should pop some suggestions. Play around with BackgroundColor and ForegroundColor
* There is also a command to output a small and annoying sound, it's unlikely you'll need to know this for the exam, and your teachers will most likely hate it.
* console.beep 'plain beep
* console.beep(2000,500) 'beep at 2000Hz for 0.5 seconds
* Find out more about the console command on the MSDN website

## Inputs

To make your program interactive you'll need your user to input commands, for the exam these will most likely be text instructions or reading from a file (covered later). You might look at buttons and games controllers next year. In VB.NET there are two types of input command that you need to know:
Let's take a look at a quick example of where this might be used:
Please insert you name: Ali Hello Ali
There is also the console.ReadKeycommand that reads in a single character. Take a look at this example:
Please select from options 1,2,3 or 4: 4 You chose : 4
In Python there is just the one command for reading user input from the keyboard which is input. Here's an example:
which if you type in your name as Alice will give the following:
Please enter your name: Alice Hello Alice
* Exercise: Inputs and Outputs
* What does the following code output:
* console.writeline("The ")
* console.write("Cat")
* console.write("sat ")
* console.writeline("on ")
* console.writeline("the " & "mat")
* Answer:
* Code Output
* The
* Catsat on
* the mat
* dim num as integer = 19
* console.writeline("The average age ")
* console.write("of a combat soldier ")
* console.write("in Vietnam was " & num)
* Answer:
* Code Output
* The average age
* of a combat soldier in Vietnam was 19
* Write code to display the following to the screen:
* Code Output
* My favourite colours:
* Red
* Blue
* Answer:
* console.writeline("My favourite colours:")
* console.writeline("Red")
* console.writeline("Blue")
* What would the following look like:
* dim age as string
* dim name as integer
* console.writeline("Enter your name: ")
* age = console.readline
* console.writeline("Enter your age: ")
* name = console.readline
* console.writeline("Hello " & name & ". You are " & age & " years old ")
* for the input:
* John
* 16
* Answer:
* Code Output
* Enter your name: John
* Enter your age: 16
* Hello 16. You are John years old
* Whoops! Fix this:
* Answer:
* dim age as integer
* dim name as string
* console.writeline("Enter your name: ")
* name = console.readline
* console.writeline("Enter your age: ")
* age = console.readline
* console.writeline("Hello " & name & ". You are " & age & " years old ")