2.2 Programming Fundamentals Flashcards

(48 cards)

1
Q

Define variable

A

A value stored in memory that can change while the program is running

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

Define constant

A

A value that does not change while the program is running, and is assigned when the program is designed

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

Define assignment

A

Giving a variable or constant a value

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

Define casting

A

Converting a variable from one data type to another

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

Define input

A

A value is read from an input device e.g. keyboard

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

Define output

A

Data generated by the computer and displayed to the user

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

Advantages of constants

A

1) make a program easier to read as they are declared and assigned at the top of the program
2) can be changed easily by the programmer in one place in a program
3) instead of changing every instance of a value throughout a program
4) so less chance of errors
5) compiler can optimise code
6) which makes a program run more quickly

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

Why is casting needed?

A

Inputs from the keyboard are always characters (multiple characters are called strings). However, for calculations, the ALU must use numbers so the string is cast to a number.

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

What is sequence?

A

Executing one instruction after another

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

What is selection?

A

A program branching depending on a condition

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

What is iteration?

A

Repeating sections of code

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

When are FOR loops used?

A

Count-controlled loops. Used when the number of iterations needed is known ahead of the iteration executing.

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

When are WHILE loops used?

A

Condition-controlled loops. Used when the number of iterations is not known because the variable used to determine when the iteration ends is changing within the iteration itself

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

When are DO…UNTIL loops used?

A

An alternative to WHILE where the code executes at least once before the condition is checked

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

Casting to an integer

A

int()

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

Casting to a real/float

A

real()/float()

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

Casting to boolean

A

bool()

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

Casting to a string

A

str()

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

Casting to ASCII

A

ASC(b)

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

Casting to a character

21
Q

Example of a FOR loop

A

for rolls in range():

22
Q

Example of a WHILE loop

A

while answer != “Computer”:
answer = input(“Pass: “)
endwhile

23
Q

Example of a DO…UNTIL loop

A

do
answer = input(“Pass: “)
until answer == “Computer”

24
Q

Example of NOT

A

end_of_file = False
while not end_of_file

25
Example of AND
end_of_file = False found = False while not end_of_file and not found
26
Example of OR
if x==2 or x==4 while choice <1 or choice <3
27
Why is casting necessary?
Casting is necessary so that sub-problems receive data in a format they are expecting. Casting allows numbers to be manipulates as strings and inputs that are always strings to become numbers.
28
Examples of casting
x = str(x) casts the variable x to a string x = int(x) casts the variable to an integer
29
What are telephone numbers stored as?
Strings. If the telephone no. was stored as an integer, we would lose the leading 0. Telephone numbers are also often entered with other symbols which aren't integers e.g. (07548) 433-844
30
string manipulation (python) - string length
length = len(string)
31
string manipulation - uppercase
ustring = string.upper()
32
string manipulation - lowercase
lstring = string.lower()
33
string manipulation - substrings
chars = string[2:3]
34
string manipulation - getting number from ascii
ascii = ord("A")
35
string manipulation - getting character from ascii
char = chr("65")
36
example someText = "Computer Science" print(len(someText)) print(someText[3:6].upper())
16 PUT
37
What is string manipulation?
The act of manipulating, extracting, or changing the characters in a string variable
38
What is concatenation?
When strings are joined to form new strings (often done with the + operator)
39
file handling - opening a file (not python)
file = open("file.txt")
40
file handling - creating a new file (not python)
newFile("myfile.txt")
41
file handling - writing lines (not python)
winners.writeLine()
42
file handling - reading lines (not python)
winners.readLine()
43
file handling - stop reading/signify end of file (not python)
winners.endOfFile()
44
file handling - closing a file (not python)
winners.close()
45
file handling - opening a file to read (python)
f = open("files.txt", "r")
46
file handling - opening a file to write to/append (python)
f = open("files.txt","a")
47
file handling - opening a file to create a new file/overwrite contents (python)
f = open("files.txt","w")
48
file handling - close file (python)
f.close()