Module 6 & 7 Flashcards
(28 cards)
The majority of programs do the following (3 Key Components)?
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
List 3 advantages of using functions.
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
Describe the differences between a value-returning function and a void function.
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.
An element consists of a(n) _______________, followed by a colon, followed by a value.
key
If the key does not exist, it will be added to the dictionary, along with value as its _____________________value.
associated
Each _____________ that is stored in a dictionary has two parts: a key and a value.
element
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:
pop
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.
specified
If the ______________________is not found, the method returns a default value.
key
Which method returns all the values in the dictionary as a sequence of tuples?
values method
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?
popitem method
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.
pop method
Which method returns all the keys in a dictionary as a sequence of tuples?
keys method
Which method returns all the keys in a dictionary and their associated values as a sequence of tuples?
items method
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?
get method
Which method clears the contents of a dictionary?
clear method
The following example is a result of using what string operation?
1 »_space;> message = ‘Hello ‘ + ‘world’ [Enter]
2 »_space;> print(message) [Enter]
3 Hello world
4 »_space;>
Concatenation
Term meaning once something has been created, it cannot be changed.
Immutable
A____________is a group of statements that exist within a program for the purpose of performing a specific task.
function
Name the benefits of using functions within your code.
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.
The code for a function is known as a______________.
function definition
To create a function, you write its________________.
definition
An_____________is any piece of data that is passed into a function when the function is called.
argument
A_______________ is a variable that receives an argument that is passed into a function.
parameter