<< Chapter < Page Chapter >> Page >
This module contains review questions and answers keyed to the module titled Itse1359-1280-Function Arguments.

Table of contents

Preface

This module is one in a collection of modules on Python designed for teaching ITSE 1359 Introduction to Scripting Languages: Python at Austin Community College in Austin, TX.

This module contains review questions and answers keyed to the module titled Itse1359-1280-Function Arguments .

Once you study that module, you should be able to answer the review questions in this module.

The questions and the answers in this module are connected by hyperlinks to make it easy for you to navigate from the question to the answer and back again.

(Note to blind and visually impaired students: with the exception of two bitmap images that are used solely as spacers to separate the questionsection from the answer section, all of the material in this module is presented in plain text format and should be accessible using an audio screen reader or abraille display. Note however that the required indentation may not be properly represented by an audio screen reader.)

Questions

Question 1

True or False? The code in Figure 1 produces the output shown in Figure 2 .

Figure 1 . Question 1 program code.
def listModifier(listA,listB): """Illustrates pass by value or reference"""print("In listModifier") print("Use incoming parameter to append to listA")listA.append(3.14159) print("New listA = " + str(listA))print("Assign a new list to listB") listB = ["A","new","list"]print("New listB = " + str(listB)) return#End function definition #Call the functionprint("Create two lists") aList = ["ab","cd","ef"]bList = ["The","old","list"] print("aList = " + str(aList))print("bList = " + str(bList)) print("Call listModifier")listModifier(aList,bList) print("Back from listModifier")print("aList = " + str(aList)) print("bList = " + str(bList))
Figure 2 . Question 1 possible output.
Create two lists aList = ['ab', 'cd', 'ef']bList = ['The', 'old', 'list'] Call listModifierIn listModifier Use incoming parameter to append to listANew listA = ['ab', 'cd', 'ef', 3.14159] Assign a new list to listBNew listB = ['A', 'new', 'list'] Back from listModifieraList = ['ab', 'cd', 'ef', 3.14159] bList = ['A', 'new', 'list']

Go to answer 1

Question 2

True or False? The code in Figure 4 produces the output shown in Figure 5 .

Figure 4 . Question 2 program code.
def listModifier(listA,listB=["B"],listC=["C"],listD=["D"]):"""Illustrates default arguments""" print("In listModifier")listA.append(1.00001) print("listA = " + str(listA))listB.append(2.00002) print("listB = " + str(listB))listC.append(3.00003) print("listC = " + str(listC))listD.append(4.00004) print("listD = " + str(listD))return #End function definitionaList = ["ab","cd","ef"] bList = ["The","old","list"]cList = ["This old house"] dList = ["is falling down"]print("aList = " + str(aList)) print("bList = " + str(bList))print("cList = " + str(cList)) print("dList = " + str(dList))print("Call listModifier") listModifier(aList,bList,dList)print("Back from listModifier") print("aList = " + str(aList))print("bList = " + str(bList)) print("cList = " + str(cList))print("dList = " + str(dList))

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Itse 1359 introduction to scripting languages: python. OpenStax CNX. Jan 22, 2016 Download for free at https://legacy.cnx.org/content/col11713/1.32
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Itse 1359 introduction to scripting languages: python' conversation and receive update notifications?

Ask