functions Flashcards

1
Q

a group of statements that exist within a program for the purpose of performing a specific task is a …….

A

function

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

a design technique that helps to reduce the duplication of code within a program is ……..

A

code reuse

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

the first line of a function is known as the ………

A

header

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

you ……. a function to execute it

A

call

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

a design technique that programmers use to break down an algorithm into functions is known as …….

A

top-down design

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

a ……. is a diagram that gives a visual representation of the relationships between functions in a program

A

hierarchy chart

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

a ……… is a variable that is created inside a function

A

local variable

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

a ……… is the part of a program in which a variable may be accessed

A

scope

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

an ………. is a piece of data that is sent into a function

A

argument

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

a ………… is a special variable that receives a piece of data when a function is called

A

parameter

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

a variable that is visible to every function in a program file is a ……..

A

global variable

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

when possible you should avoid using …….. variables in a program

A

global

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

library function

A

this is a pre-written function that is built into a programming language

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

‘random()’

A

this standard library function returns a random integer within a specified range of values
and/or
this standard library function returns a random floating-point number in the range of 0.0 up to but not including 1.0

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

‘uniform()’

A

this standard library function returns a random floating-point number within a specified range of values

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

‘return’

A

this statement causes a function to end and sends a value back to the part of the program that called the function

17
Q

datagram chart

A

this is a design tool that describes the input, processing and output of a function

18
Q

Boolean

A

this type of function returns true or false

19
Q

differentiate

A

this is a maths module function

20
Q

How do functions help you to reuse code in a program?

A

They let you perform the same operations over and over without having to retype every line of the implementation.

21
Q

Name and describe the two parts of a function definition.

A

The header is the first line of a function definition and it defines the name and any parameter variables. The body defines what the function does.

22
Q

When a function is executing, what happens when the end of the function block is reached?

A

At the end of the function block, the program goes back to the place where the function was called and continues executing statements from that point. Using the standard nomenclature, we say that control returns to the point that the function was called.

23
Q

What is a local variable? What statements are able to access a local variable?

A

A local variable is a variable that is defined inside a function block without the global keyword. The only statements that are able to access a local variable are those that come after it within the same function block.

24
Q

What is a local variable’s scope?

A

everywhere below the point the variable is defined that is within the same function as the variable

25
Q

Why do global variables make a program difficult to debug?

A

Global variables make programs difficult to debug because when you find that you’re getting the wrong value in one, it’s hard to narrow down where the error is coming from.

26
Q

What library function would you use to select a random number from;
0, 5, 10, 15, 20, 25, 30 ?

A
you would use the 'randrange()' function from the 'random' module
specifically 'random.randrange(0, 31, 5)'
27
Q

What statement do you have in a value-returning function?

A

The difference between a void function and a value-returning function is the existence of a ‘return’ statement in a value-returning function. This statement sends some value back to the point in the program where the function was called.

28
Q

What three things are listed on an IPO chart?

A

Input: a brief description of the parameters of the function

Processing: a brief description of what the function is supposed to do

Output: a brief description of what value(s) the function returns

Note that the input and/or output columns may be empty, depending on what you want the function to do.

29
Q

What is a Boolean function?

A

one that returns either ‘True’ or ‘False’

30
Q

What are the advantages of breaking a large program into modules?

A
  1. If you’ve defined a bunch of functions, then by putting those in separate module files you won’t have to scroll past them to see the mainline logic of your program.
  2. Splitting a program into modules where each module is a collection of related functions makes it easier to reuse code between programs. You may find that you have several programs that all need to perform the same astronomy calculations (you’re an astronomer in this example), so the module you’ve created with a bunch of astronomy functions will be useful to import into each of them.
  3. Once you’ve used a module for a while, you can be pretty sure you’ll have worked out all the bugs in it. So it reduces the possibility of bugs.
  4. When working in a group, it’s both easier and more useful for each coder to work on a single module of related functions than on some random selection of functions/ sections of code.
31
Q

What is a function?

A

A function is a group of statements that exist within a program for the purpose of performing a specific task.

32
Q

What is an argument?

A

any piece of data that is passed into a function when the function is called

33
Q

What is a parameter?

A

a variable that receives an argument that is passed into a function