Show
Programming basicsProgramming is writing computer code to create a program, in order to solve a problem. To program a computer, you need to know how programs are constructed. Each variable is named so it is clear which variable is being used at any time. It is important to use meaningful names for variables: For example, The name given to each variable is up to the programmer, but
ideally a variable name should have meaning, ie it should reflect the value that it is holding. There are some rules about variable names: Consider these example variable names, all of which could be variable names to store the length of a side of a square:
ExampleThis Python (3.x) program uses two meaningful names when calculating the perimeter of a square: >>> side_length = 5
>>> perimeter = side_length * 4
>>> print(perimeter)
20 Because meaningful names have been used in this code, it is easy to know what each variable is used for. Data typesVariables come in all shapes and sizes. Some are used to store numbers, some are used to store text and some are used for much more complicated types of data. The data types to know are:
In many programming languages variables must be declared before they can be used, for example:
In some languages, such as Python, you can simply start using the variable without declaring it.
KS3 Subjects
Which of the following is a valid reason for giving variables meaningful?Which of the following is a valid reason for giving variables meaningful names in a program? A programmer will find it easier to read and understand the code since they will know what the variables represent.
What is a reason for the importance of variables in programming?Variables are used to store information to be referenced and manipulated in a computer program. They also provide a way of labeling data with a descriptive name, so our programs can be understood more clearly by the reader and ourselves. It is helpful to think of variables as containers that hold information.
Why is it important to use good naming variables for each data?Each variable is named so it is clear which variable is being used at any time. It is important to use meaningful names for variables: For example, pocketMoney = 20 means that the variable 'pocketMoney' is being used to store how much pocket money you have.
Which statement describes a good variable name in a program?A good variable name should: Be clear and concise. Be written in English. A general coding practice is to write code with variable names in English, as that is the most likely common language between programmers.
|