Paper 2: Key Programming Techniques Flashcards

1
Q

What is the correct syntax for the print function in Python?

A

print is always lower case and any message goes inside the brackets and inside “ ”

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

What are the rules for naming variables in Python?

A

Variables can be any word or letter, but cannot start with a number. Variables never go in “ ”.

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

What is required when taking user inputs in Python?

A

Inputs always have a variable to store the data entered. The question to ask goes in “ ”.

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

What is Casting in Python?

A

Specifying what type of number we want e.g. Integer or Float/Real (Decimal numbers).

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

What is concatenation in Python?

A

Joining string variables together using a +. Cannot use a + between words and numbers; use a , instead.

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

What is string manipulation?

A

Changing the way a word looks. Concatenation is part of this, and we can also cut out different parts of a string.

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

How do you cut a string in Python?

A

By using a start point, end point (goes up to but does not include), and step.

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

What is the purpose of if, elif, and else statements?

A

Used to make choices in the code. elif allows for more than one choice, and else goes at the end.

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

What does == signify in Python?

A

It checks if two values are the same.

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

What is a nested if statement?

A

Putting an if statement inside another if statement.

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

What are case statements used for?

A

An alternative to if/elif/else but not available in Python; each case must be a single value.

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

What are for loops in Python?

A

Count controlled loops with a fixed start and end point, using a range instruction.

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

What is the range instruction in Python?

A

It creates a set of numbers with a start number, an end number (not printed), and a step.

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

What is the purpose of the in instruction in for loops?

A

It is used to break a sentence into its individual parts.

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

What are while loops in Python?

A

Condition controlled loops that keep running while the condition is true.

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

What does != mean in Python?

A

Not Equal to.

17
Q

What is a do until loop?

A

Code runs until the criteria is met, running at least once before checking the criteria.

18
Q

What is an array in Python?

A

Similar to lists, they store multiple values using the same variable name but can only store one type of data.

19
Q

How do you access items in an array?

A

Using its index number, with the first element at index 0.

20
Q

What are functions and procedures in Python?

A

Sub programs that split a program into smaller sections; functions return a value, while procedures do not.

21
Q

What is the purpose of parameters in functions?

A

Values sent from the main program to be used in the sub program.

22
Q

What is the first step in reading from a file?

A

Open the file and specify if you are reading or writing (‘r’, ‘w’).

23
Q

What function is used to read an entire file into a variable?

A

file.read()

24
Q

What must be done after reading from a file?

A

Close the file using file.close().

25
Q

What is required to write to a file in Python?

A

Open the file again using ‘w’ to overwrite or ‘a’ to add text.

26
Q

What are global variables?

A

Variables available in both the main program and functions/procedures without needing to be passed as parameters.

27
Q

How do you generate random numbers in Python?

A

Use random(start, end) to generate a number starting at start and going up to and including the end number.