Python Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What it is the syntax for a print statement when using a variable

A

print(variable name)

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

What it is the syntax for a print statement when using a string

A

print(“string”)

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

what is the command for the user to input data

A

input()

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

what is the command to allow the user to input a hole number value

A

int(input())

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

What is the command for allowing the user to enter a decimal value

A

float(input())

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

what are the two types of loop

A

While loop

For loop

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

What is the syntax for a while loop

A

while counter

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

What is the syntax for a for loop

A

For counter in range(0,5):

print(counter)

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

Define Pseudocode

A

Pseudocode is an informal high-level description of the operating principle of a computer program or other algorithm. It uses the structural conventions of a programming language, but is intended for human reading rather than machine reading.

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

How is Pseudocode started and ended in a python shell

A

’’’

’’’

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

What is the command for calling a function

A

functionname()

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

What is string slicing and what is it used for

A

String slicing is used for either removing locating items in a string

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

State the commands used in string slicing

A

x = y[w:z]
Purpose: To extract characters from the middle of a string.

x = y[-z:]
Purpose: To return characters to the right of a string.

x = y[:z]
Purpose: To return characters to the left of a string

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

Name the nine Logical operators that can be used in if elif and else statements

A
== equals 
!= does not equal 
 greater than 
>= greater than or equal to 
and both conditions must be true
or one condition must be true
not condition is not true
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Name the 7 arithmetic operations

A
\+ addition
- subtraction
* multiplication
/ division 
** power of 
// integer division  
% modulus (remainder after division)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the syntax for creating a list

A

x = []

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

What is the command for inserting to a list

A

listname.append(item)

18
Q

What is the command for removing an item from a list

A

listname.Remove(item)

19
Q

What is the command for sorting a list

A

listname.sort()

20
Q

What is the command for reverses the order of the items in a list

A

listname.reverse

21
Q

What is the command for removing all items from a list

A

del listname[:]

22
Q

What is the command for returning a list if it contains a specific value or item

A

if x in listname:

23
Q

Name the two types of variables

A

Global

Local

24
Q

Give the syntax for a global variable

A

global=0

25
Q

Give the syntax for a local variable

A
def function: 
    variable_name=variable_info
26
Q

How to begin a serial file

A

text_file = open(“filename”, “w”)

27
Q

Name the command for input the data of a serial file into a variable.

A

x = textfile.read()

28
Q

Name the command for Reads a single line of data from an open file into x.

A

variable = LineInput(1)

29
Q

Name the command for writing a single item of data to an open file.

A

Example code: textfile.write(“data to write”)

30
Q

Name the command that commits any data in the file buffer to storage and closes the file. If a file is not closed, data will not be written.

A

textfile.close

31
Q

Define the try keyword

A

‘Try’ is the keyword to put before a run time error is likely to occur

32
Q

Define the except keyword

A

The code following ‘except’ is the code

to execute if an error occurs.

33
Q

What is the syntax for try

A

try:

34
Q

What is the syntax for except

A

except:

35
Q

Give the syntax for a if statement

A

if …. :

36
Q

Give the syntax for an else statement

A

else:

37
Q

Give the syntax for ending an if statement in pseudocode

A

Endif

38
Q

Give the syntax for ending a function in pseudocode

A

Endfunction_name

39
Q

Name the three types of error in programming

A

Syntax errors when you mistype a keyword, the program doesn’t recognise it as a valid
command and will not run.

Logic errors where the program runs but you get the wrong result, perhaps not always
consistently! Logic errors are called bugs.

Run-time errors that occur in exceptional circumstances such as division by zero and
incorrect data type input. These should be trapped with exception handling commands

40
Q

Name the types of validation

A

Presence checks: did the user actually enter any data?
Range checks: does the input fall within a valid range of numbers?
Format check: does the input match a recognised format, e.g. LLNN NLL for postcode
Length check: is the input the required length of characters, e.g. minimum 8 character
password