Unit Test — Unit test Answers

1 verified answers
1
Free Preview

Readable code

A
is written in large font.
B
is written neatly in straight columns.
C
is easy to understand and useful to other programmers working with the code.
D
is password protected so that only authorized programmers can access it.
2
Free Preview

What does the program print out as a result of the given snippet of code?supplies = ["pencil", "notebook", "backpack", "calculator", "pen"]print(len(supplies))

A
5
B
8
C
[‘backpack’, ‘calculator’, ‘notebook’, ‘pen’, ‘pencil’]
D
[‘pencil’, ‘notebook’, ‘backpack’, ‘calculator’, ‘pen’]
3

Which set of variables will make code easier to understand?

A
a, b, c
B
sum, price, count
C
xii, xix, xxi
D
x, y, z
4

What happens when a Boolean expression is evaluated?

A
If the condition evaluates as True, then the next statement is executed.
B
If the condition evaluates as True, then nothing happens.
C
If the condition evaluates as False, then the next statement is false.
D
If the condition evaluates as False, then the next statement is executed.
5

What does this snippet of code do?birds = ["robin", "finch", "grackle", "crow", "wren"] for i in birds:print(i)

A
It counts the number of birds in the list.
B
It prints the index and then each bird name.
C
It prints each bird name on a separate line.
D
It prints each index number on a separate line.
6

Which syntax error in programming is unlikely to be highlighted by a compiler or an interpreter?

A
a variable name misspelling
B
a missing space
C
a comma in place of a period
D
a missing closing quotation mark
7

Python programmers use the Else statement to run code

A
when all the conditions in the preceding If and Elif statements evaluate as False.
B
when the first condition evaluates as True and the second condition evaluates as False.
C
when the code needs to be executed every time the program is run.
D
when the code needs to be executed for conditions that evaluate as True.
8

Comments should

A
give the reader the background of the programmer.
B
be written for every line of code.
C
communicate the purpose of the code that follows it.
D
give information about how many hours it took to write the code.
9

Read the code below. What will the computer print if the input for year_variable is 1700?if year_variable == 1776: print("Your answer is correct. The Declaration of Independence was signed in “year_variable”.")elif year_variable 1776: compute_variable = year_variable - 1776 print("Subtract “compute_variable” years from your answer for the correct answer.")

A
Your answer is incorrect. The Declaration of Independence was signed in 1776.
B
Subtract 76 years from your answer for the correct answer.
C
Add compute_variable years to your answer for the correct answer.
D
Add 76 years to your answer for the correct answer.
10

Which is true of diagnosing and troubleshooting?

A
Diagnosing attempts to identify the source of a problem, while troubleshooting looks for the nature of the problem.
B
Diagnosing is used to fix problems with hardware, while troubleshooting is used to fix problems in program code.
C
Diagnosing looks for the nature of the problem, while troubleshooting attempts to identify the source of the problem.
D
Diagnosing is used to fix problems in program code, while troubleshooting is used to fix problems with hardware.
11

What does this loop that uses a range function do? for i in range(7, 15):print(“goodbye”)

A
It prints “goodbye” 8 times, numbered from 7 through 14.
B
It prints “goodbye” 9 times, numbered from 7 through 15.
C
It prints “goodbye” 9 times.
D
It prints “goodbye” 8 times.
12

An unexpected result is returned by the computer when a program is executed. Which has likely occurred?

A
an error
B
a compiler
C
an interpreter
D
a stepping function
13

Which printout will result from the snippet of code?supplies = ["pencil", "notebook", "backpack", "pen", "calculator"]print("These are the supplies in the list:\n", supplies)

A
[‘pencil’, ‘notebook’, ‘backpack’, ‘pen’, ‘calculator’]
B
These are the supplies in the list: [‘pencil’, ‘notebook’, ‘backpack’, ‘pen’, ‘calculator’]
C
These are the supplies in the list: [‘pencil’, ‘notebook’, ‘backpack’, ‘pen’, ‘calculator’]
D
These are the supplies in the list:\n [‘pencil’, ‘notebook’, ‘backpack’, ‘pen’, ‘calculator’]
14

A stepping function allows a program

A
to determine its own variables.
B
to be inspected line by line.
C
to translate code between programming languages.
D
to identify problems in code by searching for correct syntax.
15

Indenting the start and finish of segments

A
requires the new programmers to insert comments of their own.
B
requires a lot of extra effort for the programmer.
C
makes the flow of the program more difficult to follow.
D
makes the flow of the program easier to follow.
16

While running a program, Sasha enters a negative number when a positive value was expected. Which type of error is likely to occur?

A
syntax
B
run-time
C
logic
D
interpreter
17

Which argument forces a writer to return to and change the input before resolving a “UnicodeError”?

A
errors= “strict”
B
errors= “fix”
C
errors= “ignore”
D
errors= “replace”
18

Arrays are described as immutable because they

A
are two dimensional.
B
are arranged sequentially.
C
can be reordered.
D
cannot be changed once they are defined.
19

Which can be used to decode a Unicode character encoding into text?

A
stringVariable=unicodeString.decode(decoding= “utf-8”, errors= “strict”)
B
stringVariable=unicodeString.encode(encoding= “utf-8”, errors= “strict”)
C
stringVariable=unicodeString.decode(encoding= “utf-8”, errors= “strict”)
D
stringVariable=unicodeString.encode(decoding= “utf-8”, errors= “strict”)
20

The introduction of the 8-bit computer expanded the number of bytes available for encoding. This led to the development of

A
octets.
B
Apple and Xerox.
C
ASCII.
D
Unicode.

Did you find these answers helpful?