2.2. Programming fundamentals Flashcards
What is the difference between a variable and a constant
Variable - a memory location within a computer program where the values are stored
Constant - A variable that does not change during the execution of the program
How do you input and output in python
input()
print()
What are the three programming constructs
Sequence - the order that the code is in
Selection - executes lines of code if a certain condition is met, e.g. if statements
Iteration - something going on repeatedly, e.g. while/for loops
What are the two types of loops
Condition controlled - loop keeps going until a certain condition is met
Count controlled - loop keeps going for a certain amount of time
What are the arithmetic operators in python
+ - addition
- - subtraction
* - multiplication
/ - division
** - power
// - floored division
% - remainder
< - greater than
<= - greater than or equal
> - less than
>= - less than
What are the boolean operators
AND
OR
NOT
TRUE
FALSE
What are the data types
String - text
Integer - a whole number
Float - a decimal value
Boolean - can only be TRUE or FALSE
What is casting and how do you do it
When you change the data type of a variable
String - str(x)
Integer - int(x)
Float - float(x)
How do you open and close a file in python
open(fileName)
fileName.close()
What are the different methods of opening a file
“r” - read (opens a file for reading. Error if the file doesn’t exist)
“a” - append (opens a file for appending. Creates the file if it doesn’t exist)
“w” - write (opens a file for writing. Creates the file if it doesn’t exist)
“x” - create (Creates a file. Error if file exists)
What are the ways to read a file in python
print(file name.read()) - read a file
print(file name.read(number)) - read a certain number of characters
print(file name.readline()) - read a line
How do you find data using SQL
SELECT firstname,surname
FROM database
WHERE surname LIKE “S%”
How do you create a function in python and how do you call it
def function name():
functionName()
What does (2,1) mean in a 2D array
2 across
1 down