Exam 2

¡Supera tus tareas y exámenes ahora con Quizwiz!

What is the argument of the function in the following line of Python code? Biggest_Value = max("Hello world")

"Hello World"

What will the following Python program print out? smallest_so_far = -1 for the_num in [9, 41, 12, 3, 74, 15]: if the_num < smallest_so_far: smallest_so_far = the_num print smallest_so_far

-1

How many times will the body of the following loop be executed? n = 0 while n > 0: print("Lather") print("Rinse") print("Dry off!")

0

What does the break statement do?

Exits the currently executing loop.

Functions that do not return a value are called "fruitful" functions.

False

The else keyword in a while loop specifies a block of code to be executed when the loop is finished.

False

The range() function defaults to increment the sequence by 2, however it is possible to specify the increment value by adding a second parameter: range(30, 1)

False

The range(6) is not the values of 0 to 5, but the values 0 to 6.

False

What is the result of the function in the following code snippet: >>> def greet(lang): if lang == 'es': return 'Hola' elif lang == 'fr': return 'Bonjour' else: return 'Hello' >>> print(greet('en'),', Elizabeth') Hello, Elizabeth

Hello, Elizabeth

What does the continue statement do?

Jumps to the "top" of the loop and starts the next iteration.

What is a good statement to describe the is operator as used in the following if statement? if smallest is None: smallest = value

Matches both type and value

What does the following code print out? i = 1 while True: if i % 3 == 0: break print(i) i + = 1

Syntax Error

What is the result of the following code snippet: def greet(): return "Hello" print(greet(), "Elizabeth") >>> print(greet('Elizabeth')) Hello, Elizabeth

There is no return value

What does the following code print out? True = False while True: print(True) break

This causes an error.

What is wrong with this Python loop? n = 5 while n > 0: print(n) print("All done")

This loop will run forever

A break statement can stop a while loop even if the while condition is true.

True

A for loop is used for iterating over a sequence (like a list or a string).

True

A function can be called many times with different arguments each time it is called.

True

A function is called using the function name followed by parentheses around an arguments.

True

A nested loop is a loop inside a loop.

True

A while loop will execute as long as a condition is true.

True

An argument is a value that is passed to a function as input when the function is invoked.

True

Built-in function names are treated as reserved words.

True

Calling a function is the same thing as invoking a function.

True

Functions must be defined and called separately.

True

In Python, a function is some reusable code that takes arguments(s) as input, does some computation, and then returns a result or results.

True

In most cases the "inner loop" will be executed one time for each iteration of the "outer loop".

True

The for loop does not require an indexing variable to set beforehand.

True

The looping structures we are using include for and while loops.

True

The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and ends at a specified number.

True

The return value of a function can not be assigned to a variable.

True

The two kinds of functions in Python are built-in functions and functions we define ourselves.

True

With the for loop we can execute a set of statements, once for each item in a list.

True

Which of the options is not a reason to use a function?

You want original and fresh code for every program.

What does the following code print out? fruits = ["apple", "banana", "cherry"] for x in fruits: print(x)

apple banana cherry

When parameters are given values they become _____.

arguments

What does the following code print out? for x in "banana": print(x)

b a n a n a

Which option is not a built-in function? print computepay input max

computepay

A function is defined using the reserved word define.

false

What is the iteration variable in the following Python program? friends = ["Jack", "Zero", "Sally"] for friend in friends: print ("Happy Halloween, "+friend) print("Done!")

friend

What is the argument of the function in the following line of Python code? Biggest_Value = max("Hello world")

max

What is the function in the following line of Python code? Biggest_Value = max("Hello world")

max

The arguments of a function are also called the _____ of the function.

parameters

What does the following code print out? adj = ["red", "big"] fruits = ["apple", "banana"] for x in adj: for y in fruits: print(x, y)

red apple red banana big apple big banana

The result of a function is called the _____.

return value

A function that does not return a value is a _____ function.

void

Which reserved word indicates the start of an "indefinite" loop in Python?

while


Conjuntos de estudio relacionados

Principles of Insurance and General Insurance

View Set

Section 9: Purchase and Sale Agreements - quiz

View Set