Paper 2: Key Programming Techniques Flashcards
What is the correct syntax for the print function in Python?
print is always lower case and any message goes inside the brackets and inside “ ”
What are the rules for naming variables in Python?
Variables can be any word or letter, but cannot start with a number. Variables never go in “ ”.
What is required when taking user inputs in Python?
Inputs always have a variable to store the data entered. The question to ask goes in “ ”.
What is Casting in Python?
Specifying what type of number we want e.g. Integer or Float/Real (Decimal numbers).
What is concatenation in Python?
Joining string variables together using a +. Cannot use a + between words and numbers; use a , instead.
What is string manipulation?
Changing the way a word looks. Concatenation is part of this, and we can also cut out different parts of a string.
How do you cut a string in Python?
By using a start point, end point (goes up to but does not include), and step.
What is the purpose of if, elif, and else statements?
Used to make choices in the code. elif allows for more than one choice, and else goes at the end.
What does == signify in Python?
It checks if two values are the same.
What is a nested if statement?
Putting an if statement inside another if statement.
What are case statements used for?
An alternative to if/elif/else but not available in Python; each case must be a single value.
What are for loops in Python?
Count controlled loops with a fixed start and end point, using a range instruction.
What is the range instruction in Python?
It creates a set of numbers with a start number, an end number (not printed), and a step.
What is the purpose of the in instruction in for loops?
It is used to break a sentence into its individual parts.
What are while loops in Python?
Condition controlled loops that keep running while the condition is true.
What does != mean in Python?
Not Equal to.
What is a do until loop?
Code runs until the criteria is met, running at least once before checking the criteria.
What is an array in Python?
Similar to lists, they store multiple values using the same variable name but can only store one type of data.
How do you access items in an array?
Using its index number, with the first element at index 0.
What are functions and procedures in Python?
Sub programs that split a program into smaller sections; functions return a value, while procedures do not.
What is the purpose of parameters in functions?
Values sent from the main program to be used in the sub program.
What is the first step in reading from a file?
Open the file and specify if you are reading or writing (‘r’, ‘w’).
What function is used to read an entire file into a variable?
file.read()
What must be done after reading from a file?
Close the file using file.close().
What is required to write to a file in Python?
Open the file again using ‘w’ to overwrite or ‘a’ to add text.
What are global variables?
Variables available in both the main program and functions/procedures without needing to be passed as parameters.
How do you generate random numbers in Python?
Use random(start, end) to generate a number starting at start and going up to and including the end number.