Chapter 5, Part 2 Flashcards
void function
Group of statements within a program for performing a specific task. Does not return a value to the statement that called it. When you need to perform the task, you call the function.
value-returning function
Similar to void function (group of statements within a program for performing a specific task), but also returns a value. The value is returned to part of the program that called the function when function finishes executing.
Standard library
Library of pre-written functions that comes with Python. Library functions perform tasks that programmers commonly need. print(), range() and input() are a few examples.
Modules
Files that stores functions of the standard library. To call a function stored in a module, you need to write an import statement.
Random module
Includes library functions for working with random numbers.
Dot notation
Notation for calling a function that belongs to a module.
ex: module_name.function_name()
randint function
Generates a random integer in the range provided by the arguments.
randrange function
Similar to range function, but returns randomly selected integer from the resulting sequence. You pass the same arguments as you do to the range function.
random function
Returns a random float in the range of 0.1 to 1.0. Does not receive arguments.
uniform function
Returns a random float, but allows user to specify range.
Seed value
Initializes the formula that generates random numbers. Need to use different seeds in order to get different series of random numbers. By default, system time is used for seed. Can use random.seed() to specify desired seed value.
The random numbers created by functions in the random module are actually….
….pseudo-random numbers.
How do you write a value-returning function?
To write a value-returning function, you write a simple function and add one or more return statements at the end of the function definition.
Name 3 reasons why value-returning functions can be useful in specific situations.
- You can have the function prompt the user for input and return the user’s input.
- Simplify mathematical expressions.
- Complex calculations that need to be repeated throughout the program.
IPO chart
Describes the input, processing and output of the function. An IPO chart is a tool for designing and documenting functions.
Boolean function
Returns either True or False. Used to test a condition such as for repetition or decision structures.
How do you return multiple values?
In Python, a function can return multiple values.
Ex: return expression 1, expression 2, expression 3, etc.
When you call such a function in an assignment statement, you need to have an equal number of variable names on the left side of the assignment operator to receive the returned values.
math module
part of standard library that contains functions that are useful for performing mathematical calculations.
Modularization
Grouping related functions in modules. Makes program easier to understand, test, and maintain.
In large, complex programs, it is important to keep code organized.
Menu-driven program
Displays a list of operations on the screen, allowing the user to select the desired operation.