quiz 4.2

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What is the index of 7 in this list? [5, 6, 10, 7, 3, 2.5]

3

What will you see on the next line? >>> aList = [12, 3, 5, 7, 7] >>> aList.index(7)

3

What is the output? def divide(numA, numB): return numA / numB answer = divide(21,3) print (answer)

7.0

Which statement is true? Select 3 options.

The definition of a function must come before where the function is used. A function can have more than one parameter. A function can use variables as parameters.

For the program shown, choose the correct word to complete the sentence. def divide(numA, numB): quotient = numA / numB return quotient # the main part of your program that calls the function numC = 40 numD = 5 answer = divide(numC, numD) print("Quotient: ", answer) print (numA)

The variable ____numA____ scope is local to the divide function.

What will happen if you enter the following code in IDLE? >>> aList = [10, 23, 'bye', 4.6] >>> aList.sort()

You will see an error statement since you cannot sort a list with both string and numeric data.

The output of the range function is a sequence, which is a list of integers. range(3) creates which sequence of numbers?

[0, 1, 2]

What will you see on the next line? >>> myList = [5, 6, 10, 6, 32] >>> myList.remove(6) >>> myList

[5, 10, 6, 32]

function

a group of instructions that can be used to organize a program or perform a repeated task

return value

a value that can be passed from a function back to the calling part of a program

parameter

a value that can be passed to a function

_________ divide(numA, numB): _______ numA / numB

def return

Which function will find the difference of 15 and 3 and return 12 when the main part of your program has the following line of code? answer = subtract(15,3)

def subtract(numA, numB): return numA - numB

In the program below, numA is a _____. def multiply(numA, numB): product = numA * numB return product answer = multiply(8,2) print (answer)

parameter

Choose the function required to have the code have the output shown. >>> aList = [10, 23, 'bye', 4.6] >>> aList._______() 4.6 >>> aList [10, 23, 'bye']

pop

For the function below, which variables have the same scope? def square(numA, numB): return numA ** numB base = 5 power = 2 answer = square (base,power) print(answer)

power and base

The _____ of a variable is determined by which parts of a program can view and change its value.

scope

In the program below, which variable has the same scope as strA? def usernameMaker (strFirst, strLast): return strFirst + strLast[0] def passwordMaker (strA, numC): if len(strA) > 4: answer = dogName[0:3] return answer + str(numC) else: return 'xk&' + str(numC) # the main part of your program that calls the function username = usernameMaker ('Chris', 'Smith') dogName = 'Sammy' favoriteNumber = 7 password = passwordMaker (dogName,favoriteNumber) print ("Username is ",username) print ("Password is ",password)

strA and numC have the same scope

In the program below, what is the scope of strFirst? def usernameMaker (strFirst, strLast): return strFirst + strLast[0] def passwordMaker (strA, numC): if len(strA) > 4: answer = dogName[0:3] return answer + str(numC) else: return 'xk&' + str(numC)

the function usernameMaker


Ensembles d'études connexes

Mod 12: Sex, Gender, and Sexuality

View Set

Chapter 22: Seizing an American Empire

View Set

Terry Paul 3250 Marketing Final Exam Quizzes

View Set

MARK. 4380 Marketing Research Exam 1

View Set

Property and casualty insurance Exam Questions and Answers Part one

View Set

Murach's HTML5 & CSS3 Study Guide's

View Set