2.2. Programming fundamentals Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is the difference between a variable and a constant

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you input and output in python

A

input()
print()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the three programming constructs

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the two types of loops

A

Condition controlled - loop keeps going until a certain condition is met
Count controlled - loop keeps going for a certain amount of time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the arithmetic operators in python

A

+ - addition
- - subtraction
* - multiplication
/ - division
** - power
// - floored division
% - remainder
< - greater than
<= - greater than or equal
> - less than
>= - less than

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the boolean operators

A

AND
OR
NOT
TRUE
FALSE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the data types

A

String - text
Integer - a whole number
Float - a decimal value
Boolean - can only be TRUE or FALSE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is casting and how do you do it

A

When you change the data type of a variable

String - str(x)
Integer - int(x)
Float - float(x)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you open and close a file in python

A

open(fileName)
fileName.close()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the different methods of opening a file

A

“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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the ways to read a file in python

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you find data using SQL

A

SELECT firstname,surname
FROM database
WHERE surname LIKE “S%”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you create a function in python and how do you call it

A

def function name():

functionName()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does (2,1) mean in a 2D array

A

2 across
1 down

How well did you know this?
1
Not at all
2
3
4
5
Perfectly