The second quiz will cover the following topics:
Conditional Execution
Iteration
The quiz will consist of definitions, short answers, translation, code evaluation, debugging, and programming sections.
Below are examples of the type of questions that may be asked on the quiz. It is meant to be representative, rather than exhaustive (ie. there may be questions that show up on the quiz that are not shown below).
Briefly define the following terms.
Boolean Expression
Exception
Short Circuit Evaluation
Infinite Loop
while
loop instead of a
for
loop:numbers = [5, 4, 7, 0, 1]
count = 0
for number in numbers:
if number:
break
count += 1
for i in range(0, 10):
if i < 4:
continue
elif i == 7:
break
else:
print i
print i
1
and 100
(inclusive) that are also a multiple of 5
, but
it contains some errors. Identify and fix the errors:while i < 100:
if i % 2 or i % 5:
total + 1
print total
Given a list of random integers, numbers
, write Python code that
computes the sum of all the numbers between a
and b
(inclusive) and
prints the resulting total.
Write Python code that prints 'Yeah' if a number n
is between the values a
and b
(inclusive). Otherwise, print 'Nope'.
Write Python code that generates n
random numbers (between 0
and 9
), counts the number of odd and even numbers, and then prints out the totals.
Write Python code that computes the list of the even numbers between 0
and 100
that are also a multiple of 7
.
Write Python code that simulates rolling a die until we a get a 6
and
reports how many rolls it took.