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
What is the function of the comparison operator
Less than - checks if one value is less than another
What is the function of the comparison operator <=?
Less than or equal to - checks if one value is less than or equal to another
What is the function of the comparison operator >?
Greater than - checks if one value is greater than another
What is the function of the comparison operator >=?
Greater than or equal to - checks if one value is greater than or equal to another
True or False: Comparison operators can only be used to compare numbers
False, these operators can be used with strings as well as numbers. The strings are compared alphabetically
Boolean Operator: AND
Ensures that the overall statement is true only of *all* the individual statements are true
Boolean Operator: OR
Ensures that the overall statement is true if *any* of the individual statements are true
Boolean Operator: NOT
Used to reverse the logical state of the other operators
In programming, what does sequence do?
Ensures that the commands are executed in the correct order
In programming, what does selection do?
Chooses between two or more options. Involves the use of combinations of if, else and elseif statements
When can if/else be used in programming?
if/else statements can be used if there are only two possible outcomes.
Why are elseif statements more efficient in programming?
As soon as the correct condition is found, none of the rest of the options are checked
Why are else statements used in programming?
To state what should happen if none of the options in the if or elseif statements are true
What are nested if statements?
If statements that are completely within another if statement
Every if statement always needs its own _____ statement
endif
_________ is the process of repeating a set of instructions for a fixed number of times or until there is a desired outcome. It is executed by program constructs called loops
Iteration
What is count controlled iteration?
Iteration used when the number of iterations is known before the loop is started
What is a condition controlled iteration?
Iteration used when the number of times a loop is executed is determined by a condition
Are while loops an example of count controlled iteration, condition controlled iteration or can they be either?
While loops can be count controlled or condition controlled
Are for loops an example of count controlled iteration or condition controlled iteration?
Count controlled
Are do…until loops an example of count controlled iteration or condition controlled iteration?
Condition controlled
What do for loops do?
Instruct the loop to be executed for a set number of times
What do condition controlled while loops do?
Continue while a condition remains true and stops when it becomes false
What makes a count controlled while loop less efficient than a for loop?
More lines of code are needed
What do do… until loops do?
Continue until a condition becomes true
In a while loop the variable to be tested must be ________ ___ _____ _ _____ before the loop is started
Declared and given a value (initialised)
What must happen each time a while loop is ran?
Must be incremented or decremented
What is the difference between a while loop and a do… until loop?
In a while loop the condition is tested at the start of the loop whereas in a do… until loop it is tested at the end and will therefore be run at least once
What does concatenated mean?
Combined
Why must computers be aware of data types of values stored in variables?
So that data is interpreted and manipulated correctly
What is an integer?
A number without a fraction or decimal. Integers can be positive or negative
Give an example of an integer
Any whole number eg 0, 3, 100, 10369
What is a real number?
All numbers that exist and their fractions and decimals
Are integers real numbers?
Yes
Why is it more efficient to declare integers as integers?
So that less memory is needed
What are real numbers declared as in pseudocode/python?
‘float’
Give an example of a real number
Any number, including decimals, such as 2, 3.9, 6.632, 9.37352
What is a character?
A single letter, number or symbol
Give an example of a character
Any letter, number or symbol eg C, 3, !
What can a string hold?
A list of characters of any length
What are strings enclosed in?
Single or double quotation marks
Give an example of a string
Anything enclosed in single or double quotation marks eg “Hello user3 your password is ?1pass69word”
Data used by a computer are presented in strings of…
1s and 0s
What happens if a computer is not told the data type?
It will not be able to use it correctly eg it may try to multiply text and display numbers as images
Data types must be declared in all/some programming languages
Some