Module 6 & 7 Flashcards

1
Q

The majority of programs do the following (3 Key Components)?

A

INPUT: Get data from the user (direct or indirect)
keyboard, GUI, file
database, Web service

PROCESS: transform the input
count, sum, extract, etc.
derive, generate

OUTPUT: Put the result of the transformation somewhere
screen, GUI, file
database, Web service

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

List 3 advantages of using functions.

A

Simplify code
Code reuse
Better (easier) testing
Faster development
Easier facilitation of teamwork
WAR → Integrate with other tools
- Field calculators (ArcGIS Pro and QGIS)
- Task/Tools in ArcGIS Pro
- Label Expressions in ArcGIS Pro and QGIS

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

Describe the differences between a value-returning function and a void function.

A

A value-returning function has a return statement that returns a value back to the part of the program that called it.

When you call a void function, it simply executes the statements it contains and then terminates.

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

An element consists of a(n) _______________, followed by a colon, followed by a value.

A

key

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

If the key does not exist, it will be added to the dictionary, along with value as its _____________________value.

A

associated

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

Each _____________ that is stored in a dictionary has two parts: a key and a value.

A

element

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

The_______method returns the value associated with a specified key and removes that key-value pair from the dictionary. If the key is not found, the method returns a default value. Here is the method’s general format:

A

pop

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

When the method is called, it returns the value that is associated with the___________________ key, and it removes that key-value pair from the dictionary.

A

specified

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

If the ______________________is not found, the method returns a default value.

A

key

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

Which method returns all the values in the dictionary as a sequence of tuples?

A

values method

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

Which method returns, as a tuple, the key-value pair that was last added to the dictionary. Themethod also removes the key-value pair from the dictionary?

A

popitem method

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

Which method returns the value associated with a specified key and removes that key-value pair from the dictionary? If the key is not found, the method returns a default value.

A

pop method

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

Which method returns all the keys in a dictionary as a sequence of tuples?

A

keys method

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

Which method returns all the keys in a dictionary and their associated values as a sequence of tuples?

A

items method

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

Which method gets the value associated with a specified key. If the key is not found, the method does not raise an exception. Instead, it returns a default value?

A

get method

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

Which method clears the contents of a dictionary?

A

clear method

17
Q

The following example is a result of using what string operation?
1 &raquo_space;> message = ‘Hello ‘ + ‘world’ [Enter]
2 &raquo_space;> print(message) [Enter]
3 Hello world
4 &raquo_space;>

A

Concatenation

18
Q

Term meaning once something has been created, it cannot be changed.

A

Immutable

19
Q

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

A

function

20
Q

Name the benefits of using functions within your code.

A

Simpler Code
A program’s code tends to be simpler and easier to understand when it is broken down into functions. Several small functions are much easier to read than one long sequence of statements.

Code Reuse
Functions also reduce the duplication of code within a program. If a specific operation is performed in several places in a program, a function can be written once to perform that operation, then be executed any time it is needed. This benefit of using functions is known as code reuse because you are writing the code to perform a task once, then reusing it each time you need to perform the task.

Better Testing
When each task within a program is contained in its own function, testing and debugging becomes simpler. Programmers can test each function in a program individually, to determine whether it correctly performs its operation. This makes it easier to isolate and fix errors.

Faster Development
Suppose a programmer or a team of programmers is developing multiple programs. They discover that each of the programs perform several common tasks, such as asking for a username and a password, displaying the current time, and so on. It doesn’t make sense to write the code for these tasks multiple times. Instead, functions can be written for the commonly needed tasks, and those functions can be incorporated into each program that needs them.

Easier Facilitation of Teamwork
Functions also make it easier for programmers to work in teams. When a program is developed as a set of functions that each performs an individual task, then different programmers can be assigned the job of writing different functions.

21
Q

The code for a function is known as a______________.

A

function definition

22
Q

To create a function, you write its________________.

A

definition

23
Q

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

A

argument

24
Q

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

A

parameter

25
Q

A global_________is accessible to all the functions in a program file.

A

variable

26
Q

Why do global variables make debugging difficult?

A

Any statement in a program file can change the value of a global variable. If you find that the wrong value is being stored in a global variable, you have to track down every statement that accesses it to determine where the bad value is coming from. In a program with thousands of lines of code, this can be difficult.

27
Q

An________________is an error that occurs while a program is running, causing the program to abruptly halt. You can use the try/except statement to gracefully handle exceptions.

A

exception

28
Q

The___________gives information regarding the line number(s) that caused the exception.

A

traceback