Local vs. Global variables

¡Supera tus tareas y exámenes ahora con Quizwiz!

A variable declared in the main code is a ______ variable.

Global

Code a statement that assigns the value returned by a function to a global variable.

age = checkAge()

Code the first line of a function that implicitly declares two local variables.

def doSomething(param1, param2):

Code a function without parameters that does nothing but create two local variables.

def makeVars(): firstVar = 2 secondVar = 9

Code a function without parameters that creates two local variables and does nothing with them. Then it (unwisely) assigns the number 10 to a global variable that you've made up without a *return* statement.

def reckless(): safeVariable1 = 2 safeVariable2 = 3 global unsafeVariable unsafeVariable =10

Code something called *useless* that does nothing but create *valueless*, which has local scope.

def useless(): valueless = 0

The only place where a local variable has a value is within the ________ where it is declared.

function

Code a statement that passes the values of two global variables to a function and anticipates that the function will return a value to be assigned to a new global variable. The global variable hasn't been declared beforehand.

globalVar = processNums(num1, num2)

A parameter is a ________ variable.

local

A variable declared in a function is a ________ variable.

local

Code a statement that passes the value of a local variable to a global variable in the main code.

return total

Global and local variables differ in their _______

scope


Conjuntos de estudio relacionados

chapter 7 membrane function and structure

View Set

NBDHE: Oral and maxillofacial radiology

View Set

Health Psychology Connect Notes: Chapter 5 Part 1

View Set

Introduction to Industry and Company Analysis

View Set

History Scientist in the Development of Atomic Theory

View Set

Advanced Accounting Final Exam Part 2

View Set