Python 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

25
Give the syntax for a local variable
``` def function: variable_name=variable_info ```
26
How to begin a serial file
text_file = open("filename", "w")
27
Name the command for input the data of a serial file into a variable.
x = textfile.read()
28
Name the command for Reads a single line of data from an open file into x.
variable = LineInput(1)
29
Name the command for writing a single item of data to an open file.
Example code: textfile.write("data to write")
30
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.
textfile.close
31
Define the try keyword
‘Try’ is the keyword to put before a run time error is likely to occur
32
Define the except keyword
The code following ‘except’ is the code | to execute if an error occurs.
33
What is the syntax for try
try: | …
34
What is the syntax for except
except: | …
35
Give the syntax for a if statement
if .... :
36
Give the syntax for an else statement
else: | ...
37
Give the syntax for ending an if statement in pseudocode
Endif
38
Give the syntax for ending a function in pseudocode
Endfunction_name
39
Name the three types of error in programming
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
Name the types of validation
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