Computer Science - 2A Programming Basics

studied byStudied by 0 people
0.0(0)
Get a hint
Hint

Data type

1 / 50

flashcard set

Earn XP

Description and Tags

51 Terms

1

Data type

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

New cards
2

New cards
3

Typical memory usage: integer

2 bytes

New cards
4

Typical memory usage: float/real

4 bytes

New cards
5

Typical memory usage: character

1 byte

New cards
6

Typical memory usage: string

1 byte per character

New cards
7

Typical memory usage: boolean

theoretically 1 bit, usually 1 byte in high level languages

New cards
8

Constant

a value that does not change in a program

New cards
9

How are constants written?

in capitals, if space, use underscore

New cards
10

Snake case

the way constants are written

New cards
11

How do we declare constants in Python?

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

New cards
12

How do we declare constants in pseudocode?

CONSTANT [IDENTIFIER] ← [value]

New cards
13

Why declare a constant? [2]

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

New cards
14

Can a constant change its value? [2]

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

New cards
15

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

- STRING_TO_INT(x)
- x ← x as INT

New cards
16

Output length of string (pseudocode, Python)

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

New cards
17

Output substring (pseudocode, Python)

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

New cards
18

Output position of character (pseudocode, Python)

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

New cards
19

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

New cards
20

Concatenate

link together (strings)

New cards
21

Convert character to ASCII function (pseudocode)

CHAR_TO_CODE(a)

New cards
22

Convert to uppercase (Python)

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

New cards
23

Find datatype of variable (Python)

print(type([identifier]))

New cards
24

Uses of comments [3]:

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

New cards
25

Common data types [5]

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

New cards
26

(check if it is) equal to

==

New cards
27

(check if it is) not equal to

!=

New cards
28

less than

<

New cards
29

greater than

>

New cards
30

less than or equal to

<=

New cards
31

greater than or equal to

>=

New cards
32

Declare a variable

defining it for the first time

New cards
33

Reference a variable

use the identifier in code to have in calculations or lists

New cards
34

Nested statements

a statement inside another statement

New cards
35

AND

returns True if both values are True

New cards
36

OR

returns True if at least one value is True

New cards
37

NOT

returns True if value is False

New cards
38

Random integer (pseudocode, Python)

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

New cards
39

Definite iteration

a process that repeats a set number of times

New cards
40

Indefinite iteration

a process that repeats until a certain condition is met

New cards
41

Example of definite iteration

for loops

New cards
42

Example of indefinite iteration

while loops

New cards
43

WHILE loops have the condition tested at the top/bottom

top

New cards
44

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

bottom

New cards
45

Array

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

New cards
46

Qualities of array [2]:

- fixed length
- declare length when created

New cards
47

Qualities of list [2]:

- variable length
- can append onto list

New cards
48

Output length of array (pseudocode, Python)

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

New cards
49

2D array

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

New cards
50

Reference an item in a 2D array

array[i][j]

New cards
51

Record

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

New cards

Explore top notes

note Note
studied byStudied by 7 people
... ago
5.0(1)
note Note
studied byStudied by 1 person
... ago
5.0(1)
note Note
studied byStudied by 85 people
... ago
5.0(1)
note Note
studied byStudied by 15 people
... ago
5.0(1)
note Note
studied byStudied by 3 people
... ago
5.0(2)
note Note
studied byStudied by 5 people
... ago
5.0(2)
note Note
studied byStudied by 18 people
... ago
5.0(1)
note Note
studied byStudied by 426 people
... ago
5.0(1)

Explore top flashcards

flashcards Flashcard (50)
studied byStudied by 57 people
... ago
5.0(1)
flashcards Flashcard (34)
studied byStudied by 45 people
... ago
5.0(1)
flashcards Flashcard (68)
studied byStudied by 2 people
... ago
5.0(1)
flashcards Flashcard (110)
studied byStudied by 37 people
... ago
5.0(3)
flashcards Flashcard (20)
studied byStudied by 4 people
... ago
5.0(3)
flashcards Flashcard (99)
studied byStudied by 15 people
... ago
4.0(1)
flashcards Flashcard (54)
studied byStudied by 12 people
... ago
5.0(1)
flashcards Flashcard (38)
studied byStudied by 11 people
... ago
5.0(1)
robot