Computer Science - 2A Programming Basics

0.0(0)
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/50

flashcard set

Earn XP

Description and Tags

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

51 Terms

1
New cards

Data type

indicates the type of data that can be stored in a field

2
New cards

3
New cards

Typical memory usage: integer

2 bytes

4
New cards

Typical memory usage: float/real

4 bytes

5
New cards

Typical memory usage: character

1 byte

6
New cards

Typical memory usage: string

1 byte per character

7
New cards

Typical memory usage: boolean

theoretically 1 bit, usually 1 byte in high level languages

8
New cards

Constant

a value that does not change in a program

9
New cards

How are constants written?

in capitals, if space, use underscore

10
New cards

Snake case

the way constants are written

11
New cards

How do we declare constants in Python?

(no way to make unchangeable variable)
[IDENTIFIER] = [value]

12
New cards

How do we declare constants in pseudocode?

CONSTANT [IDENTIFIER] ← [value]

13
New cards

Why declare a constant? [2]

- prevents value from being accidentally changed by code
- shows programmer that value should remain the same

14
New cards

Can a constant change its value? [2]

- not while the program is running
- can be changed before program is compiled or translated

15
New cards

Change a value's datatype in pseudocode [2]:

- STRING_TO_INT(x)
- x ← x as INT

16
New cards

Output length of string (pseudocode, Python)

string = [any string]
- OUTPUT(LEN(string))
- print(len(string))

17
New cards

Output substring (pseudocode, Python)

string = [any string]
- OUTPUT(SUBSTRING([start], [end], string))
- print(string[[start]:[end]:[step]])

18
New cards

Output position of character (pseudocode, Python)

string = [any string]
- OUTPUT(POSITION(string, [character]))
- print(string.rfind([character]))

19
New cards

Concatenate string (pseudocode, Python)

string1 = [any string]
string2 = [any string]
new_string = [combination of string1 and string2]
- new_string ← string + string2
- new_string = string + string2

20
New cards

Concatenate

link together (strings)

21
New cards

Convert character to ASCII function (pseudocode)

CHAR_TO_CODE(a)

22
New cards

Convert to uppercase (Python)

string = [any string]
print(string.upper())

23
New cards

Find datatype of variable (Python)

print(type([identifier]))

24
New cards

Uses of comments [3]:

- describe the purpose of programs
- state program's author
- explain what code does

25
New cards

Common data types [5]

- integer
- float/real
- character
- string
- boolean

26
New cards

(check if it is) equal to

==

27
New cards

(check if it is) not equal to

!=

28
New cards

less than

<

29
New cards

greater than

>

30
New cards

less than or equal to

<=

31
New cards

greater than or equal to

>=

32
New cards

Declare a variable

defining it for the first time

33
New cards

Reference a variable

use the identifier in code to have in calculations or lists

34
New cards

Nested statements

a statement inside another statement

35
New cards

AND

returns True if both values are True

36
New cards

OR

returns True if at least one value is True

37
New cards

NOT

returns True if value is False

38
New cards

Random integer (pseudocode, Python)

- RANDOM_INT(0, 100)
- import random
random.randint(1, 100)

39
New cards

Definite iteration

a process that repeats a set number of times

40
New cards

Indefinite iteration

a process that repeats until a certain condition is met

41
New cards

Example of definite iteration

for loops

42
New cards

Example of indefinite iteration

while loops

43
New cards

WHILE loops have the condition tested at the top/bottom

top

44
New cards

REPEAT...UNTIL loops have the condition tested at the top/bottom

bottom

45
New cards

Array

data structure that allows you to hold many items of data which is referenced by one identifier

46
New cards

Qualities of array [2]:

- fixed length
- declare length when created

47
New cards

Qualities of list [2]:

- variable length
- can append onto list

48
New cards

Output length of array (pseudocode, Python)

- OUTPUT(LEN(array))
- print(len(array))

49
New cards

2D array

an array of an arrays arranged in a grid format, accessed using two index values

50
New cards

Reference an item in a 2D array

array[i][j]

51
New cards

Record

data structure consisting of a number of fields which can be of different types