Python - Chapter 5

Ace your homework & exams now with Quizwiz!

How do functions help you reuse code in a program.

If a specific operation is performed in several places in a program, a function can be written once to perform that operation and then be executed any time it is needed.

A set of statements that belong together as a group and contribute to the function definition is known as a(n) ________.

block

Write the definition of a function printGrade, which takes one parameter containing a string value and returns nothing. The function prints "Grade: " followed by the string parameter.

def printGrade(value): print("Grade:", value)

What is a function?

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

What is a parameter?

A parameter is a variable that receives an argument that is passed

What is an argument?

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

What are the benefits of modularizing a program with Functions

Simpler Code, Code Reuse, Better Testing, Faster Development, Easier Facilitation of Teamwork

True/False: Different functions can have local variables with the same names.

True

True/False: Python function names follow the same rules for naming variables.

True

When a function is called by its name, then it is ________

executed

How can functions make the development of multiple programs faster?

Functions can be written for the commonly needed tasks, and those functions can be incorporated into each program that needs them.

What is meant by the phrase "divide and conquer"?

When a large program is written as several small functions, each one performing a specific part of the task. These small functions can then be executed in the desired order to perform the overall task.

A(n) ________ is any piece of data that is passed into a function when the function is called.

argument

How can functions make it easier for programs to be developed by teams of programmers.

different programmers can be assigned the job of writing different functions.

A ________ constant is a global name that references a value that cannot be changed.

global

It is recommended that programmers should avoid using ________ variables in a program when possible.

global

The first line in the function definition is known as the function ________.

header

A(n) ________ variable is created inside a function.

local

A variable's ________ is the part of a program in which the variable may be accessed.

scope

Write the code to call the function named send_signal. There are no parameters for this function.

send_signal()


Related study sets

management chapter 15 practice questions

View Set

Chapter 12: Gender, Sex, and Sexuality

View Set

Chapter 30- The Americas in the Age of Independence

View Set

Oceanography Chapter 4 Study Guide

View Set

Assignment: Chapter 16 Mastering Financial Management

View Set

Questions you've gotten wrong on insurance test

View Set