Code Flashcards

(15 cards)

1
Q

To find max

A

Max = var[0]
For i in range (len(array)):
If var[i] > Max:
Max = var[i]
Display Max

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

Code for finding Min

A

Min = var[0]
For i in range (len(array)):
If var[i] < Min:
Min = var[i]
Display Min

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

Linear search code

A

Values = []
Searchvalue =
Index = 0
Found = false

While found == False and not end of list:
If values[i] == Searchvalue
Found = true
Else:
Add i to index

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

Count occurrences

A

Numbers = []
Criteria = 0
For i in range (len(array)):
If number[i] > criteria
Add 1 to criteria

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

Modulus
Code to find the remainder

A

Answer = a%b

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

Code to start a function/ procedure

A

def getData():
return …
result = getData()

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

Advantages of modular programming

A

Less code to be written - sub programs can be used multiple times
Improves readability
Splits programs into manageable chunks

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

To repeat for length of array

A

For i in range (len(array)):

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

Code round

A

(round(array))

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

Round up
Round down

A

(math.ceil(array))
(math.floor(array))

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

Substrings

A

Print (variable[0:4])
(Up to fourth integer)

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

To make a class

A

Class = className:
Val1 = 0
Val2 = “”
Val3 = 0.0

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

Code to multiply the class template

A

List = [className()]*12

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

How to read from file

A

File = open(“filename.txt”,”r”)
File.close()

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

How to write into file

A

File = open(“fileName.txt”,”w”)
File.write (texttowrite)
File.close()

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