Py4e: Chapter 4

Ace your homework & exams now with Quizwiz!

In the following Python code, which of the following is an "argument" to a function? x = 'banana' y = max(x) print(y)

x

In Python, how do you indicate the end of the block of code that makes up the function?

You de-indent a line of code to the same indent level as the def keyword

In Python what is the input() feature best described as?

a built in function

What does the following Python code print out? (Note that this is a bit of a trick question and the code has what many would consider to be a flaw/bug - so read carefully). def addtwo(a, b): added = a + b return a x = addtwo(2, 7) print(x)

2

What will the following Python code print out? ef func(x) : print(x) func(10) func(20)

10 20

What is the most important benefit of writing your own functions?

Avoiding writing the same non-trivial code more than once in your program

Which Python keyword indicates the start of a function definition?

def

Which line of the following Python program will never execute? def stuff(): print('Hello') return print('World') stuff()

print('World')

What will the following Python program print out? def greet(lang): if lang == 'es': return 'Hola' elif lang == 'fr': return 'Bonjour' else: return 'Hello' print(greet('fr'),'Michael')

Bonjour Michael

What does the following code print out? def thing(): print('Hello') print('There')

There


Related study sets

Direct Object Pronouns: Referring to Previously Mentioned People and Objects

View Set

Securities Registration (Other Rules)

View Set

Macro economics: Chapter 1 study example questions

View Set

Chpt. 11 Promoting a healthy work environment

View Set