chap 8 - overall Flashcards

(16 cards)

1
Q

explain each thing when explaining assignment

A

eg. c = a + b
- c: variable
- +: addition of a and b
- =: assignment of variable

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

conditional statement to get something in between value

A

eg. if (0 < username <10):

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

and & or conditional statements

A

eg. if ( age> 10 and age< 20):
eg. if ( age> 10 or age< 20):

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

when checking for discounts, always put bigger no. first

A

if total > 1000;
discount = total *0.2
elif total > 500:
discount = total *0.1

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

use of loops

A

use same algorithm for diff. inputs

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

types of loops

A

-for (count controlled) - knows how many times to run - doesn’t check condition
-while (pre condition) - checks iterating value before running - use for validation
-repeat until - post condition loop

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

basic structure of loops

A

-initializer- variable which controls if loop is done or not
-action
-stopping condition
-updating counter/ no. loops

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

define array

A

-a sequence of elements of the same data type
-each element has an index value
-arrays cannot be implemented on python so just think of them like list with 1 data type

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

difference btw 1D & 2D array in terms of memory

A

1D - data is stored randomly in memory cell = more comparisons to find them
2D - data is stored consecutively in memory cell = less comparisons to find them

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

what is a 2D list

A

a list made up of lists
eg.
meats = [“chicken”, “fish”, “turkey”]
groceries = [fruits, groceries, meats]

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

searching algorithm - linear search

A

-compare target value with elements from left to right until they match (can be used for sorted or unsorted list)

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

sorting algorithm - bubble sort

A

-start with 1 chosen element
-compares adjacent elements to the chosen element and swaps them if needed until it is no longer needed
-use a temporary value to swap elements

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

procedure

A

does not return value

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

function

A

returns value

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

parameter

A

variables that store the values of arguments passed in procedure/ functions (values next to defining the procedure/ function), where the arguments go

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

arguments

A

values passed in function/ procedure