Module 3
Module 3
Help
Python Basics for Data Science
You are taking "Final Exam" as a timed exam. Show more 00:47:06
Previous Next
x = "Gone"
if x == "Go":
print('Go')
else:
print('Stop')
print('Mike')
Stop Mike
Go Mike
Mike
Go Stop
Answer
Correct: Correct! The if clause executes first, followed by the last print statement.
Question 2
1.0/1.0 point (graded)
Which of the following is the value of x after the following lines of code?
x=1
x = x>5
False
1
True
Answer
Correct: The condition is false as the value of x is less than 5.
Question 3
1.0/1.0 point (graded)
What is the output of the following few lines of code?
x = 5
while x != 2:
print(x)
x = x - 1
Answer
Correct: The loop breaks when x equals 2.
Question 4
1.0/1.0 point (graded)
What is the result of running the following lines of code?
class Points(object):
def __init__(self, x, y):
self.x = x
self.y = y
def print_point(self):
print('x=', self.x, ' y=', self.y)
p1 = Points("A", "B")
p1.print_point()
x=y=
y=B
x=A y=B
x=A
Answer
Correct: The print statement will display the two values as 'x=1 y=2.
Question 5
1.0/1.0 point (graded)
What is the output of the following few lines of code?
1 AA
2 BB
3 CC
0A
1B
2C
0A
2B
4C
0 AA
1 BB
2 CC
Answer
Correct:
The enumerate function adds a counter to an iterable, allowing you to loop through both the elements and their corresponding indices.
Question 6
0.0/1.0 point (graded)
What is the result of running the following lines of code?
class Points(object):
def __init__(self, x, y):
self.x = x
self.y = y
def print_point(self):
print('x=', self.x, ' y=', self.y)
p2 = Points(1, 2)
p2.x = 'A'
p2.print_point()
x=A y=A
x= A y=2
x=A, y=B
x= 1 y=2
Answer
Incorrect: Refer to the Functions video.
Question 7
1.0/1.0 point (graded)
Considering the function delta, when will the following function return a value of 1?
def delta(x):
if x == 0:
y = 1
else:
y = 0
return y
Never
Answer
Correct: Correct! The function returns value 1 when the input is 0.
Question 8
1.0/1.0 point (graded)
1.0/1.0 point (graded)
What is the output of the following lines of code?
a = 1
def do(x):
a = 100
return x + a
print(do(1))
101
102
Answer
Correct: The value of a=100 exists in the local scope of the function disregarding the value of a=1 in the global scope.
Question 9
1.0/1.0 point (graded)
Which two of the following functions will perform the addition of two numbers with a minimum number of variables? [Select two]
return(a + b)
c = a+b
return(c)
return(sum(a, b))
return(sum((a, b)))
Answer
Correct:
Partially correct! It is one of the correct options.
Partially correct! It is one of the correct options.
Submit
Question 10
1.0/1.0 point (graded)
Why is it the best practice to have multiple except statements with each type of error labeled correctly?
It is not necessary to label errors
To determine the type of error thrown and its location within the program
Answer
Correct: Multiple except statements will help in identifying each type of error.
Previous Next
Legal
Terms of Service & Honor Code
Privacy Policy
Accessibility Policy
Trademark Policy
Sitemap
Cookie Policy
Your Privacy Choices
Connect
Idea Hub
Contact Us
Help Center
Security
Media Kit