2.2 - Programming fundamentals Flashcards
What does + do?
Adds two variables
What does - do?
Subtracts two variables
What does * do?
Multiplies 2 variables
What does / do?
Divides 2 variables
What does % (MOD) do?
Outputs the remainder of the division
What does // (DIV) do?
Divides 2 variables but only shows the integer value (integer division)
What does == do?
Shows 2 strings are equal to each other
What does != do?
Shows 2 strings are not equal to each other
The 3 basic programming constructs
- Selection - the path a program takes when running based on a decision
- Sequence - executing one instruction after the other
- Iteration - the repeated execution of a section of code
What is a variable
A named memory location which stores a value that may change during the execution of the program
What is a constant
A value that cannot change when the program is run and is assigned when the program is made
What is assignment
Giving a variable or constant a value. This is done by an “=” sign
What is an identifier and rules that an identifier must follow
- The name of the variable
- It must start with a letter
- Cannot contain special characters
- Cannot have spaces
- NAme should be meaningful
Advantages of constants
- Make a program easier to read as they are declared at the start
- Can be changed in one single place instead of changing in multiple places meaning errors are reduced
- Compiler can optimise the code meaning it can be run more quickly when using constants
What is a case statement
- Where a program can branch off in several different paths depending on the value of a variable
Two forms of iteration and when are they needed
The 3 types of statements fall into these 2 categories
- Count controlled loop (for loop) - when the number of iterations is known ahead of time
- Condition controlled loop (do…until and while loops) - used when the number of iterations is notknown as the variable controlling the iteration changes within the loop itself
Difference between a do…until loop and a while loop
- While - Condition is checked AT THE TOP. In a while loop, if the condition is met before the loop, the while loop will never run
- Do…until - the code will execute AT LEAST ONCE as the exit condition is checked AT THE END.
What coomand must be used to stop a while loop
- BREAK in python
- ENDWHILE in exam question langauge
What is nesting, why is it needed and different types of it
- Including one program construct within another e.g. loop in a loop reducing the amount of code needed making it easier to edit and debug
- Nested selection - increases the number of paths at a decision point
- Nested iteration
What is casting and why is it needed
- Changing a data type of a variable from one type to another
- It allows numbers to be manipulated as strings can be