MIS 303 Chapter 4 Test 2

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

def get_volume(width, height, length=2): volume = width * height * length return volume def main(): l = 3 w = 4 h = 5 v = get_volume(l, w, h) print(v) if __name__ == "__main__": main() Refer to Code Example 4-2: If you add the following code to the end of the main() method, what does it print to the console? print(get_volume(10, 2)) Select one: a. 40 b. 20 c. 60 d. Nothing, it causes an error

a. 40

main program: import arithmetic as a def main(): num1 = 5 num2 = 6 result = a.add(num1, num2) print("The sum is", result) if __name__ == "__main__": main() arithmetic module: def add(x = 4, y = 2): z = x + y return z Refer to Code Example 4-3: What values are in x and y after the code runs? Select one: a. 5, 6 b. 9, 8 c. 20, 12 d. 4, 2

a. 5, 6

main program: import arithmetic as a def main(): num1 = 5 num2 = 6 result = a.add(num1, num2) print("The sum is", result) if __name__ == "__main__": main() arithmetic module:def add(x = 4, y = 2): z = x + y return z Refer to Code Example 4-3: What will be displayed after the code runs? Select one: a. The sum is 11 b. The sum is 6 c. The sum is 17 d. Nothing, the code causes an error

a. The sum is 11

Which of the following statements is not true about the documentation of a module? Select one: a. You can use regular Python comments to document the functions of the module. b. You can call the help() function from the interactive shell to view the documentation. c. You can use Python docstrings to document the functions of the module. d. The documentation can describe each function in the module.

a. You can use regular Python comments to document the functions of the module.

Which statement would you use to call the print_name() function from a module named address that has been imported with this statement?import address as a Select one: a. a.print_name(name) b. global.print_name(name) c. address.print_name(name) d. print_name(name)

a. a.print_name(name)

The best way to call the main() function of a program is to code Select one: a. an if statement that calls the main() function only if the current module is the main module b. an if statement that calls the main() function only if the function exists c. a while statement that calls the main() function in each loop d. main()

a. an if statement that calls the main() function only if the current module is the main module

Assuming the random module has been imported into its default namespace, which of the following could be used to simulate a coin toss where 0 = heads and 1 = tails? Select one: a. number = random.randint(0, 1) b. number = random.coin() c. number = random.random() d. number = random.randint(0, 2)

a. number = random.randint(0, 1)

Assuming the random module has been imported into its default namespace, which of the following could be used to generate a random even integer from 2 through 200? Select one: a. number = random.randrange(2, 202, 2) b. number = random.randint(2, 200, 2) c. number = random(1, 100) * 2 d. number = random.randrange(2, 200, 2)

a. number = random.randrange(2, 202, 2)

main program: import arithmetic as a def multiply(num1, num2): product = num1 * num2 result = a.add(product, product) return result def main(): num1 = 4 num2 = 3 answer = multiply(num1, num2) print("The answer is", answer) if __name__ == "__main__": main() arithmetic module: def add(x, y): z = x + y return z Refer to Code Example 4-4: The add() function is called by Select one: a. the multiply() function b. the arithmetic module c. the main() function d. the result statement

a. the multiply() function

main program: import arithmetic as a def multiply(num1, num2): product = num1 * num2 result = a.add(product, product) return result def main(): num1 = 4 num2 = 3 answer = multiply(num1, num2) print("The answer is", answer) if __name__ == "__main__": main() arithmetic module: def add(x, y): z = x + y return z Refer to Code Example 4-4: What values are in x and y after the code runs? Select one: a. 4, 3 b. 12, 12 c. 24, 24 d. 5, 6

b. 12, 12

def get_volume(width, height, length=2): volume = width * height * length return volume def main(): l = 3 w = 4 h = 5 v = get_volume(l, w, h) print(v) if __name__ == "__main__": main() Refer to Code Example 4-2: When this program runs, what does it print to the console? Select one: a. v b. 60 c. 40 d. 24

b. 60

Which of the following is not true of hierarchy charts? Select one: a. Function names should start with a verb and indicate what the functions do. b. Related functions should be combined into a single function. c. Each function should do only what is related to the function name. d. The top level box should be for the main() function.

b. Related functions should be combined into a single function.

main program: import arithmetic as a def multiply(num1, num2): product = num1 * num2 result = a.add(product, product) return result def main(): num1 = 4 num2 = 3 answer = multiply(num1, num2) print("The answer is", answer) if __name__ == "__main__": main() arithmetic module: def add(x, y): z = x + y return z Refer to Code Example 4-4: When this code runs, what does it print to the console? Select one: a. The answer is 12 b. The answer is 24 c. The answer is 7 d. The answer is 28

b. The answer is 24

A return statement Select one: a. can only be used once in each function b. can be used to return a local variable to the calling function c. must be coded within every function d. can be used to allow the function to modify the value of a global variable

b. can be used to return a local variable to the calling function

def get_username(first, last): s = first + "." + last return s.lower() def main(): first_name = input("Enter your first name: ") last_name = input("Enter your last name: ") username = get_username(first_name, last_name) print("Your username is: " + username) if __name__ == "__main__": main() Refer to Code Example 4-1: What arguments are defined by the get_username() function? Select one: a. username b. first, last c. first_name, last_name d. s, first, last

b. first, last

Which of the following statements imports a module into the default namespace? Select one: a. import temperature as t b. import temperature c. from temperature import * d. import temperature as temp

b. import temperature

Before you can use a standard module like the random module, you need to Select one: a. import the module into the global namespace b. import the module c. import the module into a custom namespace d. import the module into its default namespace

b. import the module

If you import two modules into the global namespace and each has a function named get_value(), Select one: a. the program crashes b. an error occurs c. a name collision occurs d. an exception occurs

c. a name collision occurs

To call a function, you code the function name and Select one: a. a set of parentheses that contains a list of the local variables b. a set of parentheses that contains one or more arguments c. a set of parentheses that contains zero or more arguments d. a set of parentheses

c. a set of parentheses that contains zero or more arguments

To define a function, you code the def keyword and the name of the function followed by Select one: a. a set of parentheses that contains one or more arguments b. a set of parentheses c. a set of parentheses that contains zero or more arguments d. a set of parentheses that contains a list of the local variables

c. a set of parentheses that contains zero or more arguments

A local variable is defined Select one: a. inside the main() function b. inside an if statement c. inside a function d. outside of all functions

c. inside a function

def get_username(first, last): s = first + "." + last return s.lower() def main(): first_name = input("Enter your first name: ") last_name = input("Enter your last name: ") username = get_username(first_name, last_name) print("Your username is: " + username) if __name__ == "__main__": main() Refer to Code Example 4-1: What is the scope of the variable named s? Select one: a. global b. local in main() but global in get_username() c. local d. global in main() but local in get_username()

c. local

def get_username(first, last): s = first + "." + last return s.lower() def main(): first_name = input("Enter your first name: ") last_name = input("Enter your last name: ") username = get_username(first_name, last_name) print("Your username is: " + username) if __name__ == "__main__": main() Refer to Code Example 4-1: If the user enters 'Lopez' for the first prompt in main() and 'Maria' for the second prompt, what will display? Select one: a. maria.lopez b. Lopez.Maria c. lopez.maria d. Maria.Lopez

c. lopez.maria

A file that contains reusable code is called a Select one: a. namespace b. function c. module d. hierarchy chart

c. module

To call a function with named arguments, you code the Select one: a. values that you're passing at the end of the function call, followed by the names that correspond with the values b. values that you're passing in the same sequence that the names are defined in the function c. name of each argument, an equals sign, and the value or variable that's being passed d. values that you're passing at the beginning of the function call

c. name of each argument, an equals sign, and the value or variable that's being passed

Assuming the random module has been imported into its default namespace, which of the following could possibly result in a value of 0.94? Select one: a. number = random.randint(0, 1) / 100 b. number = random.randint(0, 1) c. number = random.random() d. number = random.randfloat()

c. number = random.random()

def get_volume(width, height, length=2): volume = width * height * length return volume def main(): l = 3 w = 4 h = 5 v = get_volume(l, w, h) print(v) if __name__ == "__main__": main() Refer to Code Example 4-2: What value is passed to the height argument by the call to the get_volume() function? Select one: a. 3 b. 5 c. 2 d. 4

d. 4

To assign a default value to an argument when you define a function, you Select one: a. set the default value for the argument in the first line of code inside the function b. code the default value instead of its name in the arguments list c. code the name of the argument, the default operator (:), and the default value d. code the name of the argument, the assignment operator (=), and the default value

d. code the name of the argument, the assignment operator (=), and the default value

def get_username(first, last): s = first + "." + last return s.lower() def main(): first_name = input("Enter your first name: ") last_name = input("Enter your last name: ") username = get_username(first_name, last_name) print("Your username is: " + username) if __name__ == "__main__": main() Refer to Code Example 4-1: What function is called first when the program runs? Select one: a. get_username() b. if __name__ == "__main__" c. input("Enter your first name: ") d. main()

d. main()


संबंधित स्टडी सेट्स

Wet 111 Microbiological Contaminants Moodle Quiz

View Set

FAA Written - ADS-B surveillance systems

View Set

Organizational behavior chapters 1-13

View Set