This short exercise will cover topics relevant to GCSE computing including:
- Data Types
- User Input
Think About the Code
- Line 1 creates a variable called ‘name’ and stores the answer from the user ‘input’
- Line 2 uses ‘print’ to say Hello and outputs the contents of the ‘user’ variable
- Variable – we use the word ‘variable’ for a . Think of it as a storage box that we can put stuff into and then take it out again later.
- Data Type – in code variables can be numbers or text. We need to use the correct data types or we may create bugs. Imagine asking the computer to multiply 3 by John or even multiply 3 by seven. In both cases the computer will be confused as it can’t multiply a number by some text – so in future we may need to tell the computer the ‘Data Type’ we expect to use. In the exercise above we only used text or ‘strings’ so we did not encounter any problems.
- User Input – We used a special command called ‘input’ to prompt the user to enter some information
- Output – We used a special command called ‘print’ to show output on the screen
- Functions – In computing we usually call special commands like ‘input’ and ‘print’ functions.
Try Roll the Dice next.