2.2 Programming Fundamentals Flashcards

1
Q

What is 7 DIV 2?

A

3 - DIV means integer division in computer science.

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

What must happen before this line of code will execute? X = f.readLine()

A

f must be a pointer to an open file

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

What is the purpose of the WHERE structure in SQL?

A

to define the criteria of the records returned

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

how to convert a string into uppercase

A

string.upper()

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

how to find the length of a string

A

len(string)

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

how to return a number of characters from the beginning of the string

A

string[ : num ]

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

how to return a number of characters from the end of the string

A

string[ - num : ]

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

how to extract characters from the middle of a string

A

string[ w : z ]

starting from w, up until (not including) z

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

how to find the position of a string inside a string

A

string.find(“z”)

where z is the substring. if it is a character, the number of its position is given. if it is a string the position of the first letter is given

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

how to produce a random number

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

how to open a file

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

how to read from a file

A

x = filename.read()
contents of file is copied into x

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

how to write to a file

A

filename.write(“data to write”)

(filename is not the name of the file but the variable in the code that the file is stored in)

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

how to close a file

A

filename.close()

(filename is not the name of the file but the variable in the code that the file is stored in)

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

how to add an item to an “array”

A

array.append(item)

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

how to call an item from an “array”

A

array[index]

17
Q

how to insert an item to an “array” at position index

A

array.insert(index,item)

18
Q

how to remove an item from an “array”

A

array.remove(item)

19
Q

how to remove an item stored at a particular index in an “array”

A

array.pop(index)

20
Q

how to sort items in an “array”

A

array.sort()

21
Q

how to add an array to “array”

A

array.extend(array2)

22
Q

how to reverse the order of a list

A

array.reverse()

23
Q

how to delete all items from “array”

A

del array[:]

24
Q

how to find if a particular item is in an array

A

if item in array:

25
Q

how to read a line from a file

A

filename.readline()

(filename is the the name of the file but the variable in the code that the file is stored in)

if you want to read a specific line you can create a loop that repeats for the same number of times as the line you want

26
Q

how do you code for when you expect a code could crash

A

try:
jlajk
except:
aslka

try is the keyword for just before the code you think will crash and except is what path the code will follow if it does crash

27
Q

how to do a validation check for a number

A

while inputs.isnumeric() == False:
inputs = input(“enter a num”)

28
Q

how to turn a letter into its ascii code number

A

ord(letter)

29
Q

how to turn a number into its ascii corresponding letter

A

chr(number)