Quiz: Python Loops and Lists
Main.PythonQuiz8 History
Hide minor edits - Show changes to output
Deleted lines 97-154:
(:source lang=python:)
# A
def square_me(x)
return x^2
# B
def square_me(x)
return x**2
# C
function square_me(x)
return x**2
# D
function square_me(x) :
return x^2
# E
def square_me(x) :
return x**2
(:sourceend:)
->'''A.'''
-->(:toggle hide q4a button show="Select":)
(:div id=q4a:)
-->%red%Incorrect.%% There are 2 problems: no ":" and x^2 should be x**2
(:divend:)
->'''B.'''
-->(:toggle hide q4b button show="Select":)
(:div id=q4b:)
-->%red%Incorrect.%% No, there needs to be a ":" at the end of the first line
(:divend:)
->'''C.'''
-->(:toggle hide q4c button show="Select":)
(:div id=q4c:)
-->%red%Incorrect.%% The keyword is "def" not "function", and we need a ":"
(:divend:)
->'''D.'''
-->(:toggle hide q4d button show="Select":)
(:div id=q4d:)
-->%red%Incorrect.%% The keyword is "def" not "function"
(:divend:)
->'''E.'''
-->(:toggle hide q4e button show="Select":)
(:div id=q4e:)
-->%blue%Correct.%%
(:divend:)
Added lines 1-155:
(:title Quiz: Python Loops and Lists:)
(:keywords quiz, test, Python, list, array, loop, introduction, course:)
(:description Learning assessment on Introduction to Python with Loops and Lists.:)
----
'''1.''' A "for" loop is typically used when the number of loop cycles is known.
->'''A.''' True
-->(:toggle hide q1a button show="Select":)
(:div id=q1a:)
-->%blue%Correct.%% Use a "for" loop to cycle through a specified number of times.
(:divend:)
->'''B.''' False
-->(:toggle hide q1b button show="Select":)
(:div id=q1b:)
-->%red%Incorrect.%% Use a "while" loop when the number of cycles is based on a condition, not number of cycles.
(:divend:)
----
'''2.''' To skip an individual cycle of a for loop, the following command is used:
->'''A.''' break
-->(:toggle hide q2a button show="Select":)
(:div id=q2a:)
-->%red%Incorrect.%% break terminates the loop
(:divend:)
->'''B.''' continue
-->(:toggle hide q2b button show="Select":)
(:div id=q2b:)
-->%blue%Correct.%% continue initiates the next cycle of the loop
(:divend:)
->'''C.''' cycle
-->(:toggle hide q2c button show="Select":)
(:div id=q2c:)
-->%red%Incorrect.%% Use a "continue" statement
(:divend:)
->'''D.''' skip
-->(:toggle hide q2d button show="Select":)
(:div id=q2d:)
-->%red%Incorrect.%% Use a "continue" statement
(:divend:)
----
'''3.''' What will the following code print as a result for sum?
(:source lang=python:)
sum = 0
for i in range(5):
if i==3:
continue
sum = sum + i
print(sum)
(:sourceend:)
->'''A.''' 0
-->(:toggle hide q3a button show="Select":)
(:div id=q3a:)
-->%red%Incorrect.%% Skip the 3 for 0+1+2+4 = 7
(:divend:)
->'''B.''' 3
-->(:toggle hide q3b button show="Select":)
(:div id=q3b:)
-->%red%Incorrect.%% Skip the 3 for 0+1+2+4 = 7
(:divend:)
->'''C.''' 7
-->(:toggle hide q3c button show="Select":)
(:div id=q3c:)
-->%blue%Correct.%% Skip the 3 for 0+1+2+4 = 7
(:divend:)
->'''D.''' 10
-->(:toggle hide q3d button show="Select":)
(:div id=q3d:)
-->%red%Incorrect.%% Skip the 3 for 0+1+2+4 = 7
(:divend:)
----
'''4.''' Which of the following are valid functions in Python?
(:source lang=python:)
# A
def square_me(x)
return x^2
# B
def square_me(x)
return x**2
# C
function square_me(x)
return x**2
# D
function square_me(x) :
return x^2
# E
def square_me(x) :
return x**2
(:sourceend:)
->'''A.'''
-->(:toggle hide q4a button show="Select":)
(:div id=q4a:)
-->%red%Incorrect.%% There are 2 problems: no ":" and x^2 should be x**2
(:divend:)
->'''B.'''
-->(:toggle hide q4b button show="Select":)
(:div id=q4b:)
-->%red%Incorrect.%% No, there needs to be a ":" at the end of the first line
(:divend:)
->'''C.'''
-->(:toggle hide q4c button show="Select":)
(:div id=q4c:)
-->%red%Incorrect.%% The keyword is "def" not "function", and we need a ":"
(:divend:)
->'''D.'''
-->(:toggle hide q4d button show="Select":)
(:div id=q4d:)
-->%red%Incorrect.%% The keyword is "def" not "function"
(:divend:)
->'''E.'''
-->(:toggle hide q4e button show="Select":)
(:div id=q4e:)
-->%blue%Correct.%%
(:divend:)
(:keywords quiz, test, Python, list, array, loop, introduction, course:)
(:description Learning assessment on Introduction to Python with Loops and Lists.:)
----
'''1.''' A "for" loop is typically used when the number of loop cycles is known.
->'''A.''' True
-->(:toggle hide q1a button show="Select":)
(:div id=q1a:)
-->%blue%Correct.%% Use a "for" loop to cycle through a specified number of times.
(:divend:)
->'''B.''' False
-->(:toggle hide q1b button show="Select":)
(:div id=q1b:)
-->%red%Incorrect.%% Use a "while" loop when the number of cycles is based on a condition, not number of cycles.
(:divend:)
----
'''2.''' To skip an individual cycle of a for loop, the following command is used:
->'''A.''' break
-->(:toggle hide q2a button show="Select":)
(:div id=q2a:)
-->%red%Incorrect.%% break terminates the loop
(:divend:)
->'''B.''' continue
-->(:toggle hide q2b button show="Select":)
(:div id=q2b:)
-->%blue%Correct.%% continue initiates the next cycle of the loop
(:divend:)
->'''C.''' cycle
-->(:toggle hide q2c button show="Select":)
(:div id=q2c:)
-->%red%Incorrect.%% Use a "continue" statement
(:divend:)
->'''D.''' skip
-->(:toggle hide q2d button show="Select":)
(:div id=q2d:)
-->%red%Incorrect.%% Use a "continue" statement
(:divend:)
----
'''3.''' What will the following code print as a result for sum?
(:source lang=python:)
sum = 0
for i in range(5):
if i==3:
continue
sum = sum + i
print(sum)
(:sourceend:)
->'''A.''' 0
-->(:toggle hide q3a button show="Select":)
(:div id=q3a:)
-->%red%Incorrect.%% Skip the 3 for 0+1+2+4 = 7
(:divend:)
->'''B.''' 3
-->(:toggle hide q3b button show="Select":)
(:div id=q3b:)
-->%red%Incorrect.%% Skip the 3 for 0+1+2+4 = 7
(:divend:)
->'''C.''' 7
-->(:toggle hide q3c button show="Select":)
(:div id=q3c:)
-->%blue%Correct.%% Skip the 3 for 0+1+2+4 = 7
(:divend:)
->'''D.''' 10
-->(:toggle hide q3d button show="Select":)
(:div id=q3d:)
-->%red%Incorrect.%% Skip the 3 for 0+1+2+4 = 7
(:divend:)
----
'''4.''' Which of the following are valid functions in Python?
(:source lang=python:)
# A
def square_me(x)
return x^2
# B
def square_me(x)
return x**2
# C
function square_me(x)
return x**2
# D
function square_me(x) :
return x^2
# E
def square_me(x) :
return x**2
(:sourceend:)
->'''A.'''
-->(:toggle hide q4a button show="Select":)
(:div id=q4a:)
-->%red%Incorrect.%% There are 2 problems: no ":" and x^2 should be x**2
(:divend:)
->'''B.'''
-->(:toggle hide q4b button show="Select":)
(:div id=q4b:)
-->%red%Incorrect.%% No, there needs to be a ":" at the end of the first line
(:divend:)
->'''C.'''
-->(:toggle hide q4c button show="Select":)
(:div id=q4c:)
-->%red%Incorrect.%% The keyword is "def" not "function", and we need a ":"
(:divend:)
->'''D.'''
-->(:toggle hide q4d button show="Select":)
(:div id=q4d:)
-->%red%Incorrect.%% The keyword is "def" not "function"
(:divend:)
->'''E.'''
-->(:toggle hide q4e button show="Select":)
(:div id=q4e:)
-->%blue%Correct.%%
(:divend:)