Free Practice Quiz Question List

06 Methods and Modular Programming Online Quiz Questions

Use this free practice quiz with 20 questions to review 06 Methods and Modular Programming, test your knowledge, and prepare for your next test or exam.

20 questions
01
Choose one
1 point

A programmer wants a method to calculate a discounted price so that other code can store the result, compare it, or use it in another calculation. Which design best meets this requirement?

  1. A

    The method must print the result instead of returning it.

  2. B

    The method must return the result so the caller can use it.

  3. C

    The method must store the result in a global variable.

  4. D

    The method must define an additional parameter for the result.

02
True or false
1 point

True or false: In the code def greet(name): ... followed by greet("Maya"), name is an argument and "Maya" is a parameter.

  1. A

    True

  2. B

    False

03
Written response
1 point

What programming design process divides a complex problem into smaller subproblems, each with a focused responsibility?

04
Fill in the blank
1 point

Complete the statement: In a method definition, named inputs are called .

05
Choose one
1 point

A method contains tax = price * tax_rate and total = price + tax. What is normally true about tax and total?

  1. A

    They can be accessed directly from every method in the program.

  2. B

    They automatically become parameters of the method that called them.

  3. C

    They are normally accessible only within the method that created them.

  4. D

    They remain available globally after the method finishes.

06
Choose all
1 point

Select all characteristics that generally make a method easier to reuse.

  1. A

    It has a descriptive name.

  2. B

    It depends on a particular global variable whenever possible.

  3. C

    It accepts necessary data through parameters.

  4. D

    It returns a useful result when appropriate.

  5. E

    It must contain only one line of code.

07
True or false
1 point

True or false: If a method executes a return statement, ordinary statements written later in that same method still execute.

  1. A

    True

  2. B

    False

08
Written response
1 point

A method is defined as def add_tax(amount, rate): return amount * (1 + rate). What number does add_tax(30, 0.1) return?

09
Fill in the blank
1 point

Complete the statement: Printing, writing to a file, or changing a global variable is an example of a .

10
Choose one
1 point

A recursive method repeatedly calls itself while solving a problem. What must it include to terminate the repeated calls?

  1. A

    A global variable that stores every previous result.

  2. B

    A base case that stops the repeated calls.

  3. C

    A print statement that displays each recursive call.

  4. D

    A default parameter that changes the method name.

11
Choose all
1 point

Select all benefits that the material associates with decomposing a grade-processing program into focused methods.

  1. A

    Each method can have a narrower responsibility.

  2. B

    Methods can be tested independently.

  3. C

    Every method must handle input, calculation, display, and file storage together.

  4. D

    Errors can be isolated to a smaller section of code.

  5. E

    A change to one responsibility can often be made in its focused method.

12
Written response
1 point

What programming concept hides implementation details behind a meaningful operation such as calculate_total()?

13
Open ended
1 point

You are designing a program that processes an order. It must validate the items, calculate a total, and create a receipt. Explain how you would decompose this program into reusable methods, including how the methods should communicate and why this design is preferable to one large procedure.

14
Choose one
1 point

Given def create_label(text, prefix="Item"): followed by create_label("Notebook") and create_label("Notebook", "Product"), which result is produced by each call?

  1. A

    Both calls return Notebook because the prefix is always fixed.

  2. B

    The first call returns Item: Notebook, and the second returns Product: Notebook.

  3. C

    The first call returns Product: Notebook, and the second returns Item: Notebook.

  4. D

    Both calls cause an error because default parameters cannot be used with strings.

15
Choose one
1 point

Which statement correctly describes a variable created inside a method?

  1. A

    A variable created inside a method can normally be accessed directly from any other method.

  2. B

    A variable created inside a method is normally local to that method.

  3. C

    A parameter belongs to the caller rather than to the method being called.

  4. D

    A return value can be accessed only while the method is still running.

16
Choose one
1 point

A program must validate grades, calculate an average, assign a letter grade, and display a report. Which design best applies decomposition?

  1. A

    Put every operation in one large method so that the program has fewer method calls.

  2. B

    Create a separate method for every individual line, regardless of what that line does.

  3. C

    Divide the problem into focused methods such as validating input, calculating a result, and creating a report.

  4. D

    Store all intermediate values in global variables so that every method can use them.

17
True or false
1 point

True or false: In the method that contains it, a return statement ends the current method, so statements after the return do not execute.

  1. A

    True

  2. B

    False

18
Written response
1 point

In the definition def greet(name):, what is the programming term for name?

19
Choose one
1 point

Consider these methods:

def printed_square(number):
print(number * number)

def returned_square(number):
return number * number

What is the important difference between calling printed_square(5) and assigning result = returned_square(5)?

  1. A

    Both methods make 25 available in result because printing and returning are interchangeable.

  2. B

    Only returned_square(5) can provide 25 as a result that the caller can store.

  3. C

    Only printed_square(5) can provide 25 to the caller because printed output is automatically returned.

  4. D

    Neither method produces 25 because a method must accept at least two parameters.

20
Choose one
1 point

Given def add(first, second): return first + second, what does add(7, 4) return?

  1. A

    The call returns 3 because the second argument is subtracted from the first.

  2. B

    The call returns 28 because the arguments are multiplied.

  3. C

    The call returns 74 because the arguments are joined as text.

  4. D

    The call returns 11 because 7 is assigned to first and 4 to second.