2.2 Programming Techniques COMPLETE Flashcards
Identifier
Describe the data being stored
Short Identifier
Easier to spell correctly each time they are used
Long Identifier
Can be used if they are more descriptive e.g. firstName
True or False: Identifiers can be the same as reserved words
False, identifiers cannot be the same as reserved words such as print or while
Can variables change whilst a program is running?
Yes
Can constants change whilst a program is running?
No
How are values assigned to variables?
Values are assigned in assignment statements using the = symbol e.g. firstName = “David”
How are values assigned to constants?
Constants are assigned as cost Pi = 3.142 for example. They can then be used in calculations
Can identifiers for variables and constants change throughout a program?
No - they must be consistent throughout the program
What is used in camel case?
Upper and lower case characters (FirstName or PricePerKilo). The first word can be lower case
What is used in snake case?
Underscores are used to link words (first_name or price_per_kilo)
What is an assignment?
The association of a piece of data with a variable or constant, e.g. index = 0
Can an assignment be done as an input?
Yes (e.g. name = input(“Please enter your name”).
When can a variable be output?
At any time throughout the program
What is the function of the operator +?
Addition
What is the function of the operator -?
Subtraction
What is the function of the operator *?
Multiplication
What is the function of the operator /?
Division
What is the function of the operator MOD?
Modulus division. Returns the remainder after the division of one number by another (26 MOD 4 = 2)
What is the function of the operator DIV?
Quotient division. Returns the quotient or the lowest integer (26 DIV 4 = 6)
What is the function of the operator ^?
Exponential powers of (3^3 = 27)
MDIBAS - This is an anagram for the order of operations in a calculation. What is the correct order and what does each letter stand for?
B - Brackets I - Indices D - Division M - Multiplication A - Addition S - Subtraction
What is the function of the comparison operator ==?
Equal to - checks if two values are equal. Two equal signs are used to distinguish it from assigning a value to a variable
What is the function of the comparison operator !=?
Not equal to - checks if two values are not equal to each other
