Lesson 12 Flashcards

(21 cards)

1
Q

a function is made up of 2 parts…

A

a header
and
a body

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

header is composed of (4)

A

the keyword def
the name of the function
the list of parameters between parantheses
a colon

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

body is composed of

A

instructions for the function

can end with a return statement

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

rules for naming a function (header)

A

1st character must be a letter or an underscore
keywords or spaces cannot be used
phython distinguishes upper vs lower case
header must always end with :

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

rules for body

A

all instructions and the return statement must be indented
ends with a return value when necessary
without the return statement the result of the function is not stored

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

whats given first, conditional or mandatory parameters

A

mandatory always first.. then conditional

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

whats the form of the optional parameter

A

parx=value

rather than par1, par2

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

note: one MUST specify arguments by position. same order as parameters were given

A

-

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

PRODUCTIVE AND VOID FUNCTIONS

A

-

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

definition productive function

A

a function which performs a specific task when it ends, RETURNING A VALUE to the instruction that called it

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

what do productive functions always end with

A

a return statement

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

definition void functions

A

a function that performs a specific task, and when it ends DOESNT RETURN ANY VALUE to the instruction that called it

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

difference between productive and void functions (2)

A

the return statement (productive functions always have it, void ones dont)
the ability to return a value

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

global vs. local variable

A

reached by any instruction in the program
vs.
can be reached within its scope, in the part within which its defined

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

whats the docstring

A

a text string, on or more lines enclosed in triple quotes («

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

whats an exception

A

an exception is triggered by some type of error

17
Q

error types (3)

A

syntax error
runtime error
semantic error

18
Q

definition of syntax error

A

an error in how the code is written

told error exists and where, not how to solve it

19
Q

definition of runtime error

A

theres an error in the code, even if syntax is correct

phython shows where the error is and the cause of it

20
Q

semantic error

A

when code is executed without error messages, but results are not the corect ones i.e. inconsistent or not expected

21
Q

how are errors handled

A

most common instruction is:
try:(….)
except(….)