module 5

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

import math def main(): math.sin(math.pi) main() A. Yes B. No

No

Given the following function def nPrint(message, n): while n > 0: print(message) n -= 1 What is k after invoking nPrint("A message", k)? k = 2 nPrint("A message", k) A. 0 B. 1 C. 2 D. 3

2

Given the following function def nPrint(message, n): while n > 0: print(message) n -= 1 What is k after invoking nPrint("A message", k)? k = 2 nPrint(n = k, message = "A message") A. 0 B. 1 C. 2 D. 3

2

What will be displayed by the following code? x = 1 def f1(): global x x = x + 2 print(x) f1() print(x) A. 1 3 B. 3 1 C. The program has a runtime error because x is not defined. D. 1 1 E. 3 3

3 3

A function with no return statement returns ______. A. void B. nothing C. 0 D. None

None

Each time a function is invoked, the system stores parameters and local variables in an area of memory, known as _______, which stores elements in last-in first-out fashion. A. a heap B. storage area C. a stack D. an array

a stack

If a function does not return a value, by default, it returns ___________. A. None B. int C. double D. public E. null

none

Consider the following incomplete code: def f(number): # Missing function body print(f(5)) The missing function body should be ________. A. return "number" B. print(number) C. print("number") D. return number

return number

What will be displayed by the following code? def f1(x = 1, y = 2): return x + y, x - y x, y = f1(y = 2, x = 1) print(x, y)

3 -1

What will be displayed by the following code? x = 1 def f1(): x = 3 print(x) f1() print(x) A. 1 3 B. 3 1 C. The program has a runtime error because x is not defined. D. 1 1 E. 3 3

3 1

What will be displayed by the following code? x = 1 def f1(): y = x + 2 print(y) f1() print(x) A. 1 3 B. 3 1 C. The program has a runtime error because x is not defined. D. 1 1 E. 3 3

3 1

What will be displayed by the following code? def f1(x = 1, y = 2): x = x + y y += 1 print(x, y) f1(2, 1) A. 1 3 B. 2 3 C. The program has a runtime error because x and y are not defined. D. 3 2 E. 3 3

3 2

What will be displayed by the following code? def f1(x = 1, y = 2): x = x + y y += 1 print(x, y) f1() A. 1 3 B. 3 1 C. The program has a runtime error because x and y are not defined. D. 1 1 E. 3 3

3 3

What will be displayed by the following code? def f1(x = 1, y = 2): x = x + y y += 1 print(x, y) f1(y = 2, x = 1) A. 1 3 B. 2 3 C. The program has a runtime error because x and y are not defined. D. 3 2 E. 3 3

3 3

6.29 __________ is a simple but incomplete version of a function. A. A stub B. A function C. A function developed using botton-up approach D. A function developed using top-down approach

A stub

A variable defined outside a function is referred to as __________. A. a global variable B. a function variable C. a block variable D. a local variable

a global variable

A variable defined inside a function is referred to as __________. A. a global variable B. a function variable C. a block variable D. a local variable

a local variable

Given the following function def nPrint(message, n): while n > 0: print(message) n -= 1 What will be displayed by the call nPrint('a', 4)? A. aaaaa B. aaaa C. aaa D. invalid call E. infinite loop

aaaa

Given the following function header: def f(p1, p2, p3, p4) Which of the following is correct to invoke it? A. f(1, 2, 3, 4) B. f(p1 = 1, 2, 3, 4) C. f(p1 = 1, p2 = 2, p3 = 3, 4) D. f(p1 = 1, p2 = 2, p3 = 3, p4 = 4) E. f(1, 2, 3, p4 = 4)

f(1, 2, 3, 4) f(p1 = 1, p2 = 2, p3 = 3, p4 = 4) f(1, 2, 3, p4 = 4)

The header of a function consists of ____________. A. function name B. function name and parameter list C. parameter list

function name and parameter list

Given the following function def nPrint(message, n): while n > 0: print(message) n -= 1 What will be displayed by the call nPrint('a', 4)? A. aaaaa B. aaaa C. aaa D. invalid call E. infinite loop

infinite loop

A function _________. A. must have at least one parameter B. may have no parameters C. must always have a return statement to return a value D. must always have a return statement to return multiple values

may have no parameters

Arguments to functions always appear within __________. A. brackets B. parentheses C. curly braces D. quotation marks

parentheses

When you invoke a function with a parameter, the value of the argument is passed to the parameter. This is referred to as _________. A. function invocation B. pass by value C. pass by reference D. pass by name

pass by value

__________ is to implement one function in the structure chart at a time from the top to the bottom. A. Bottom-up approach B. Top-down approach C. Bottom-up and top-down approach D. Stepwise refinement

B. Top-down approach

What will be displayed by the following code? x = 1 def f1(): x = x + 2 print(x) f1() print(x) A. 1 3 B. 3 1 C. The program has a runtime error because x is not defined. D. 1 1 E. 3 3

C. The program has a runtime error because x is not defined.

Which of the following function headers is correct? A. def f(a = 1, b): B. def f(a = 1, b, c = 2): C. def f(a = 1, b = 1, c = 2): D. def f(a = 1, b = 1, c = 2, d):

def f(a = 1, b = 1, c = 2):

Whenever possible, you should avoid using __________. A. global variables B. function parameters C. global constants D. local variables

global variables

Which of the following should be defined as a None function? A. Write a function that prints integers from 1 to 100. B. Write a function that returns a random integer from 1 to 100. C. Write a function that checks whether a number is from 1 to 100. D. Write a function that converts an uppercase letter to lowercase.

write a function that prints integers from 1 to 100.


Set pelajaran terkait

Accounting Information Systems - Chapter 1

View Set

Unit 2 Lesson 6 States of matter

View Set

ch. 32 skin integrity and wound care

View Set

Chapter 12 Postpartum Physiological Assessments and Nursing Care

View Set

english 10b - unit 1: explore african literature lessons 1-5

View Set

Chapter 31: Caring for Clients with Disorders of the Hematopoietic System

View Set