IBM Applied AI to IBM AI Developer Professional Certificate • STUDY MODE
PRACTICE QUIZ
QUESTION 1 OF 39
what is the result of the following: 1=2
Explanation, this statement is a syntax error
A
True
B
SyntaxError:can't assign to literalCorrect Answer
C
False
QUESTION 2 OF 39
What is the output of the following code segment:
i=6
i<5
A
True
B
FalseCorrect Answer
C
SyntaxError: can't assign to literal
QUESTION 3 OF 39
What is the result of the following: 5!=5
Explanation, this is the inequality operator
A
FalseCorrect Answer
B
True
QUESTION 4 OF 39
What is the output of the following code segment: 'a'=='A'
Explanation, the equality operator is case sensitive
A
FalseCorrect Answer
B
True
QUESTION 5 OF 39
in the video, if age=18 what would be the result
A
move onCorrect Answer
B
you can enter
QUESTION 6 OF 39
in the video what would be the result if we set the variable age as follows: age= -10
A
go see Meat Loaf
B
move onCorrect Answer
C
you can enter
D
move on
QUESTION 7 OF 39
what is the result of the following: True or False
Explanation,an or statement is only False if all the Boolean values are False
PRACTICE QUIZ
A
True, an or statement is only False if all the Boolean values are FalseCorrect Answer
B
False
QUESTION 8 OF 39
what will be the output of the following:
for x in range(0,3):
print(x)
1
2 (CORRECT)
1
2
3
A
0
B
0
QUESTION 9 OF 39
what is the output of the following:
for x in ['A','B','C']:
print(x+'A')
BA
CA (CORRECT)
B
C
A
AA
B
A
QUESTION 10 OF 39
what is the output of the following:
for i,x in enumerate(['A','B','C']):
print(i,x)
1 B
2 C (CORRECT)
BB
CC
PRACTICE QUIZ
A
0 A
B
AA
QUESTION 11 OF 39
What does the following function return: len(['A','B',1]) ?
Explanation, the function returns the number of elements in the list, in this case 3.
A
3Correct Answer
B
2
C
4
QUESTION 12 OF 39
What does the following function return: len([sum([0,0,1])]) ?
A
1Correct Answer
B
0
C
3
QUESTION 13 OF 39
What is the value of list L after the following code segment is run :
L=[1,3,2]
sorted(L)
Explanation, sorted is a function and returns a new list, it does not change the list L
A
L:[1,3,2]Correct Answer
B
L:[1,2,3]
C
L:[0,0,0]
QUESTION 14 OF 39
From the video what is the value of c after the following:
c=add1(2)
c=add1(10)
Explanation, when you call the function the second time the value of c is reassigned.
A
3
B
11Correct Answer
C
14
QUESTION 15 OF 39
what is the output of the following lines of code:
def Print(A):
for a in A:
print(a+'1')
Print(['a','b','c'])
b
c
b1
c1 (CORRECT)
Explanation, the function concatenates a string
PRACTICE QUIZ
A
a
B
a1
C
a1
QUESTION 16 OF 39
Why do we use exception handlers?
A
Terminate a program
B
Write a file
C
Read a file
D
Catch errors within a programCorrect Answer
QUESTION 17 OF 39
What is the purpose of a try…except statement?
PRACTICE QUIZ
A
Crash a program when errors occur
B
Catch and handle exceptions when an error occursCorrect Answer
C
Executes the code block only if a certain condition exists
D
Only executes if one condition is true
QUESTION 18 OF 39
What is the type of the following?
["a"]
Explanation, the "a" is surrounded by brackets so it is a list.
A
str
B
listCorrect Answer
QUESTION 19 OF 39
What does a method do to an object?
A
Changes or interacts with the objectCorrect Answer
B
Returns a new values
QUESTION 20 OF 39
We create the object:
Circle(3,'blue')
What is the color attribute set to?
A
2
B
'blue'Correct Answer
QUESTION 21 OF 39
What is the radius attribute after the following code block is run?
RedCircle=Circle(10,'red')
RedCircle.radius=1
Explanation, the line of code RedCircle.radius=1 will change the radius.
A
10
B
1Correct Answer
C
'red'
QUESTION 22 OF 39
What is the radius attribute after the following code block is run?
BlueCircle=Circle(10,'blue')
BlueCircle.add_radius(20)
MODULE 3 GRADED QUIZ
A
10
B
20
C
30Correct Answer
QUESTION 23 OF 39
What is the output of the following code?
x="Go"
if(x=="Go"):
print('Go ')
else:
print('Stop')
print('Mike')
A
Go MikeCorrect Answer
B
Mike
C
Stop Mike
QUESTION 24 OF 39
What is the result of the following lines of code?
x=1
x>5
A
True
B
FalseCorrect Answer
QUESTION 25 OF 39
What is the output of the following few lines of code?
x=0
while(x<2):
print(x)
x=x+1
1 (CORRECT)
1
2
1
3
4
A
0
B
0
C
0
QUESTION 26 OF 39
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(1,2)
p1.print_point()
A
x=1;
B
x=1 y=2Correct Answer
C
y=2
QUESTION 27 OF 39
What is the output of the following few lines of code?
for i,x in enumerate(['A','B','C']):
print(i,2*x)
1 BB
2 CC (CORRECT)
1 B
2 C
2 B
4 C
A
0 AA
B
0 A
C
0 A
QUESTION 28 OF 39
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()
A
x= 1 y=2
B
x= A y=2Correct Answer
C
x=A, y=B
QUESTION 29 OF 39
Consider the function delta, when will the function return a value of 1?
def delta(x):
if x==0:
y=1
else:
y=0
return(y)
A
When the input is anything but 0
B
When the input is 1Correct Answer
C
Never
D
When the input is 0
QUESTION 30 OF 39
What is the output of the following lines of code?
a=1
def do(x):
return(x+a)
print(do(1))
Explanation, the value of a in the global scope will be used
A
2Correct Answer
B
1
C
NameError: name 'a' is not defined
QUESTION 31 OF 39
Write a function name add that takes two parameter a and b, then return the output of a + b (Do not use any other variable! You do not need to run it. Only write the code about how you define it.)
Answer:
return(a+b)
A
def add(a,b):
QUESTION 32 OF 39
Why is it best practice to have multiple except statements with each type of error labeled Explanationly?
A
Ensure the error is caught so the program will terminate
B
In order to know what type of error was thrown and the location within the programCorrect Answer
C
To skip over certain blocks of code during execution
D
It is not necessary to label errors
QUESTION 33 OF 39
What is the result of the following lines of code?
x=1
x>-5
A
TrueCorrect Answer
B
False
QUESTION 34 OF 39
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()
A
x= A
B
y= B
C
x= A y= BCorrect Answer
QUESTION 35 OF 39
What is the output of the following few lines of code?
for i,x in enumerate(['A','B','C']):
print(i+1,x)
2 B
3 C (CORRECT)
1 B
2 C
1 BB
2 CC
A
1 A
B
0 A
C
0 AA
QUESTION 36 OF 39
What is the output of the following lines of code?
a=1
def do(x):
a=100
return(x+a)
print(do(1))
Explanation, the value of a=100 exists in the local scope of the function. Therefore the value of a=1 in the global scope is not used.
A
2
B
101Correct Answer
C
102
QUESTION 37 OF 39
What is the output of the following few lines of code?
x=5
while(x!=2):
print(x)
x=x-1
4
3 (CORRECT)
4
3
2
A
5
B
5
Explanation:
the program will never leave the loop
QUESTION 38 OF 39
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=2
p2.print_point()
A
x=2 y=2Correct Answer
B
x=1 y=2
C
x=1 y=1
QUESTION 39 OF 39
Consider the function step, when will the function return a value of 1?
def step(x):
if x>0:
y=1
else:
y=0
return y
Explanation, the value of y is 1 only if x is larger than 0
A
if x is larger than 0Correct Answer
B
if x is equal to or less then zero
C
if x is less than zero
Ready to test your recall?
what is the result of the following: 1=2
Explanation, this statement is a syntax error