ENGR 102 Exam 1 Questions and
Answers 100% Solved
Which of the following represents a conditional construct? - ✔✔Does not have a loop, BUT has a branch. Question
2, Quiz 6 (the middle one)
How is repetition handled in programs? - ✔✔The loop will repeat a computation several times.
The "continue" statement is a keyword that you can put in the middle of your loop.
What does it do? - ✔✔It does not executed the below code but repeats the loop in a new iteration.
Which of the following would represent a loop? - ✔✔The one on the right with the arrow back to the top Question
4, Quiz 6 (answer C)
What will be printed when the following Python code is executed?
magic = [[4, 9, 2], [3, 5, 7], [8, 1, 6]]
diag_sum = 0 vert_sum = 0 horz_sum = 0
for i in range(3):
diag_sum += magic[i][i] vert_sum += magic[2][i] horz_sum += magic[i][1]
print(diag_sum, vert_sum, horz_sum) - ✔✔A 3x3 magic square is a 3x3 square grid filled with distinct positive
integers such that each cell contains a different integer and the sum of the
integers in each row, column and diagonal is equal. For a 3x3 grid, the following is the only unique solution.
492
357
816
Notice that the sum of any row, column or diagonal adds up to 15.
,What is printed to the console when the following Python program is executed?
a = [12.3, 25.6, 48.6] b = [78.6, 14.6, 3.5] c = b + a
print(c[1]) - ✔✔[78.6, 14.6, 3.5, 12.3, 25.6, 48.6], when lists are added, they are placed side by side, so ORDER
MATTERS.
What is the output of the following program?
language = ['P', 'y', 't', 'h', 'o', 'n'] print(language[:-4]) - ✔✔['P', 'y']
x = [] for i in range(2):
x.append(i) x += x
print(x) - ✔✔Before Loop: x = [] After Iteration 1: i = 0, x = [0, 0]
After Iteration 2: i = 1, x = [0, 0, 1, 0, 0, 1]
What will be printed when the following Python program is executed?
a = [10.0, 20.0, 30.0] b = [0, 1, 0, 2] c = 0 for i in b:
print(a[b[i]]) - ✔✔Iteration 1: i = 0, b[i] = 0, a[b[i]] = 10.0
Iteration 2: i = 1, b[i] = 1, a[b[i]] = 20.0
Iteration 3: i = 0, b[i] = 0, a[b[i]] = 10.0
Iteration 4: i = 2, b[i] = 0, a[b[i]] = 10.0
What characters are allowed when using print statements in Python? (Pick all that applies) -
✔✔letters, numbers, and underscores
The basic types of variables in Python are , floating-point, and string. -
✔✔integers
, Which of the following are valid variable names (pick one)
-Winner!
-2nd_name
-My_Name
-Gig'Em
-Gig-Em - ✔✔My_Name (does not start with a number or _ and does not have a !,',-, or space
How do you print a floating-point variable, x_value, in Python? - ✔✔print(float(x_value))
Consider the lines of code written in Python. What is the output on the screen?
=1