Incorrect! This code will only print the strings "Zap" or "ABC", not "jane" or "fred". Try again.
Zap ABC Zap
Incorrect! This would be correct if the call was fred() jane() fred(). Try again.
ABC Zap jane
Incorrect! This code will only print the strings "Zap" or "ABC", not "jane" or "fred". Try again.
ABC Zap ABC
Correct! jane() fred() jane() will print ABC Zap ABC.
Zap Zap Zap
Incorrect! This would be correct if the call was fred() fred() fred(). Try again.
3.
Q-3: What value is printed when the following code is executed?
name = "Jane Doe"
def myFunction(parameter):
value = "First"
value = parameter
print (value)
myFunction("Second")
value
Incorrect! "value" is the name of a variable. This code will print what "value" is assigned to. Try again.
Second
Correct! "value" is assigned to the value of parameter which is "Second", so that's what will print.
parameter
Incorrect! "parameter" is equal to the function call's argument. Try again.
First
Incorrect! Although the variable value is assigned to "First" initially, it is then reassigned to be equal to the parameter. Try again.
Jane Doe
Incorrect! The "name" variable is unused in the function call, so it does not affect what is printed. Try again.
4.
Q-4: A named sequence of statements is known as which of the following?
definition
Incorrect! A definition is used to create functions. Try again.
method
Incorrect! A method is a function that is defined in a class.
turtle
Incorrect! "turtle" is a specific Python module that lets you draw lines and shapes. Try again.
module
Incorrect! A module is a file that contains Python statements and definitions. Try again.
function
Correct! A function is a named sequence of statements in Python.
5.
Q-5: What will the following code print?
def pow(b, p):
y = b ** p
return y
def square(x):
a = pow(x, 2)
return a
n = 5
result = square(n)
print(result)
5
This would be true if it first printed the value of x.
10
This would be true if it printed 5 * 2 but it is 5 ** 2 which is 5 * 5.
25
It prints the value of 5 raised to the 2nd power which is 5 * 5 = 25.
32
This would be true if it was 2 raised to the 5th power (2 * 2 * 2 * 2 * 2) = 32.
3125
This would be ture if it was 5 raised to the 5th power (5 * 5 * 5 * 5 * 5) = 3125.
6.
Q-6: Consider the following Python code. What does this code print?
def rem(a, b):
return a % b
print(rem(3,7))
0
This would be true if it was rem(3,3). The value 3 would go into 3 one time with 0 remainder.
3
The value 7 goes into 3 zero times, so the remainder is 3.
7
How many times does 7 go evenly into 3 and what is the remainder?
1
This would be true if it was rem(7,3)
7.
Q-7: Which of the following would NOT work as a variable name?
a
Incorrect! a is a valid variable name. Try again.
len
Correct! This would not work as a variable name because it is already reserved as a built-in function name.
length
Incorrect! length would work as a variable because it is not a reserved word or a built-in function. Try again.
x
Incorrect! x is a valid variable name. Try again.
8.
Q-8: Consider the code below. What prints?
print(int(33.7))
34.0
Incorrect! The int function converts a floating point number to an integer. Try again.
34
Incorrect! The int function does not round up. Try again.
33.70
Incorrect! The int function converts a floating point number to an integer. Try again.
33
Correct! The int function always truncates floating point numbers.
9.
Q-9: Consider the code below. Line 1 is called…
def printWeather():
print("It is sunny!")
the function header
Correct! The first line of a function definition is the header.
the function body
Incorrect! Everything but the first line of a function definition is the function body. Try again.
the function definition
Incorrect! Lines 1 and 2 collectively are the function definition. Try again.
the function named
Incorrect! The name is printWeather.
10.
Q-10: Consider the code block below. What happens when you run this program?
repeat_lyrics()
def repeat_lyrics():
print_lyrics()
print_lyrics()
def print_lyrics():
print("I'm a lumberjack, and I'm okay.")
print('I sleep all night and I work all day.')
The lyrics print like normal.
Incorrect! An error occurs when you call a function before it is defined. Try again.
We get a TypeError.
Incorrect! This will not cause a TypeError because there is not an issue with the variable types. Try again.
We get a NameError.
Correct! You get a NameError when you call a function before it is defined.
The program compiles but nothing prints.
Incorrect! This program will not compile. Try again.