DRAG DROP
Insert the code boxes in the correct positions in order to build a line of code which asks the user for
an integer value and assigns it to the depth variable.
(Note: some code boxes will not be used.)
Explanation:
One possible way to insert the code boxes in the correct positions in order to build a line of code
which asks the user for an integer value and assigns it to the depth variable is:
depth = int(input("Enter the immersion depth: "))
This line of code uses the input function to prompt the user for a string value, and then uses the int
function to convert that string value into an integer number. The result is then assigned to the
variable depth.
You can find more information about the input and int functions in Python in the following
references:
[Python input() Function]
[Python int() Function]
A set of rules which defines the ways in which words can be coupled in sentences is called:
B
Explanation:
Syntax is the branch of linguistics that studies the structure and rules of sentences in natural
languages. Lexis is the vocabulary of a language. Semantics is the study of meaning in language. A
dictionary is a collection of words and their definitions, synonyms, pronunciations, etc.
Reference: [Python Institute - Entry-Level Python Programmer Certification]
DRAG DROP
Arrange the binary numeric operators in the order which reflects their priorities, where the top-most
position has the highest priority and the bottom-most position has the lowest priority.
Explanation:
The correct order of the binary numeric operators in Python according to their priorities is:
Exponentiation (**)
Multiplication (*) and Division (/, //, %)
Addition (+) and Subtraction (-)
This order follows the standard mathematical convention of operator precedence, which can be
remembered by the acronym PEMDAS (Parentheses, Exponents, Multiplication/Division,
Addition/Subtraction). Operators with higher precedence are evaluated before those with lower
precedence, but operators with the same precedence are evaluated from left to right. Parentheses
can be used to change the order of evaluation by grouping expressions.
For example, in the expression 2 + 3 * 4 ** 2, the exponentiation operator (**) has the highest
priority, so it is evaluated first, resulting in 2 + 3 * 16. Then, the multiplication operator (*) has the
next highest priority, so it is evaluated next, resulting in 2 + 48. Finally, the addition operator (+) has
the lowest priority, so it is evaluated last, resulting in 50.
You can find more information about the operator precedence in Python in the following references:
6. Expressions — Python 3.11.5 documentation
Precedence and Associativity of Operators in Python - Programiz
Python Operator Priority or Precedence Examples Tutorial
Which of the following expressions evaluate to a non-zero result? (Select two answers.)
AB
Explanation:
In Python, the ** operator is used for exponentiation, the / operator is used for floating-point
division, and the // operator is used for integer division. The order of operations is parentheses,
exponentiation, multiplication/division, and addition/subtraction. Therefore, the expressions can be
evaluated as follows:
A) 2 ** 3 / A - 2 = 8 / A - 2 (assuming A is a variable that is not zero or undefined) B. 4 / 2 * * 3 - 2 = 4
/ 8 - 2 = 0.5 - 2 = -1.5 C. 1 * * 3 / 4 - 1 = 1 / 4 - 1 = 0.25 - 1 = -0.75 D. 1 * 4 // 2 ** 3 = 4 // 8 = 0
Only expressions A and B evaluate to non-zero results.
Reference: [Python Institute - Entry-Level Python Programmer Certification]
DRAG DROP
Insert the code boxes in the correct positions in order to build a line of code which asks the user for a
float value and assigns it to the mass variable.
(Note: some code boxes will not be used.)
Explanation:
One possible way to insert the code boxes in the correct positions in order to build a line of code that
asks the user for a float value and assigns it to the mass variable is:
mass = float(input("Enter the mass: "))
This line of code uses the input function to prompt the user for a string value, and then uses
the float function to convert that string value into a floating-point number. The result is then assigned
to the variable mass.
You can find more information about the input and float functions in Python in the following
references:
[Python input() Function]
[Python float() Function]
Python Is an example of which programming language category?
A
Explanation:
Python is an interpreted programming language, which means that the source code is translated
into executable code by an interpreter at runtime, rather than by a compiler beforehand. Interpreted
languages are more flexible and portable than compiled languages, but they are also slower and less
efficient. Assembly and machine languages are low-level languages that are directly executed by the
hardware, while compiled languages are high-level languages that are translated into machine code
by a compiler before execution.
Reference: [Python Institute - Entry-Level Python Programmer Certification]
DRAG DROP
Drag and drop the literals to match their data type names.
Explanation:
One possible way to drag and drop the literals to match their data type names is:
STRING: “All The King’s Men”
BOOLEAN: False
INTEGER: 42
FLOAT: -6.62607015E-34
A literal is a value that is written exactly as it is meant to be interpreted by the Python interpreter. A
data type is a category of values that share some common characteristics or operations. Python has
four basic data types: string, boolean, integer, and float.
A string is a sequence of characters enclosed by either single or double quotes. A string can represent
text, symbols, or any other information that can be displayed as text. For example, “All The King’s
Men” is a string literal that represents the title of a novel.
A boolean is a logical value that can be either True or False. A boolean can represent the result of a
comparison, a condition, or a logical operation. For example, False is a boolean literal that represents
the opposite of True.
An integer is a whole number that can be positive, negative, or zero. An integer can represent a
count, an index, or any other quantity that does not require fractions or decimals. For example, 42 is
an integer literal that represents the answer to life, the universe, and everything.
A float is a number that can have a fractional part after the decimal point. A float can represent a
measurement, a ratio, or any other quantity that requires precision or approximation. For example, -
6.62607015E-34 is a float literal that represents the Planck constant in scientific notation.
You can find more information about the literals and data types in Python in the following references:
[Python Data Types]
[Python Literals]
[Python Basic Syntax]
How many hashes (+) does the code output to the screen?
C
Explanation:
The code snippet that you have sent is a loop that checks if a variable “floor” is less than or equal to
0 and prints a string accordingly. The code is as follows:
floor = 5 while floor > 0: print(“+”) floor = floor - 1
The code starts with assigning the value 5 to the variable “floor”. Then, it enters a while loop that
repeats as long as the condition “floor > 0” is true. Inside the loop, the code prints a “+” symbol to
the screen, and then subtracts 1 from the value of “floor”. The loop ends when “floor” becomes 0 or
negative, and the code exits.
The code outputs five “+” symbols to the screen, one for each iteration of the loop. Therefore, the
correct answer is C. five.
Reference: [Python Institute - Entry-Level Python Programmer Certification]
DRAG DROP
Drag and drop the conditional expressions to obtain a code which outputs * to the screen.
(Note: some code boxes will not be used.)
Explanation:
One possible way to drag and drop the conditional expressions to obtain a code which outputs * to
the screen is:
if pool > 0:
print("*")
elif pool < 0:
print("**")
else:
print("***")
This code uses the if, elif, and else keywords to create a conditional statement that checks the value
of the variable pool. Depending on whether the value is greater than, less than, or equal to zero, the
code will print a different pattern of asterisks to the screen. The print function is used to display the
output. The code is indented to show the blocks of code that belong to each condition. The code will
output * if the value of pool is positive, ** if the value of pool is negative, and *** if the value
of pool is zero.
You can find more information about the conditional statements and the print function in Python in
the following references:
[Python If … Else]
[Python Print Function]
[Python Basic Syntax]
What happens when the user runs the following code?
B
Explanation:
The code snippet that you have sent is calculating the value of a variable “total” based on the values
in the range of 0 to 3. The code is as follows:
total = 0 for i in range(0, 3): if i % 2 == 0: total = total + 1 else: total = total + 2 print(total)
The code starts with assigning the value 0 to the variable “total”. Then, it enters a for loop that
iterates over the values 0, 1, and 2 (the range function excludes the upper bound). Inside the loop,
the code checks if the current value of “i” is even or odd using the modulo operator (%). If “i” is even,
the code adds 1 to the value of “total”. If “i” is odd, the code adds 2 to the value of “total”. The loop
ends when “i” reaches 3, and the code prints the final value of “total” to the screen.
The code outputs 2 to the screen, because the value of “total” changes as follows:
When i = 0, total = 0 + 1 = 1
When i = 1, total = 1 + 2 = 3
When i = 2, total = 3 + 1 = 4
When i = 3, the loop ends and total = 4 is printed
Therefore, the correct answer is B. The code outputs 2.
Reference: [Python Institute - Entry-Level Python Programmer Certification]
What is the expected output of the following code?
C
Explanation:
The code snippet that you have sent is a conditional statement that checks if a variable “counter” is
less than 0, greater than or equal to 42, or neither. The code is as follows:
if counter < 0: print(““) elif counter >= 42: print(”“) else: print(””)
The code starts with checking if the value of “counter” is less than 0. If yes, it prints a single asterisk ()
to the screen and exits the statement. If no, it checks if the value of “counter” is greater than or equal
to 42. If yes, it prints three asterisks () to the screen and exits the statement. If no, it prints two
asterisks () to the screen and exits the statement.
The expected output of the code depends on the value of “counter”. If the value of “counter” is 10, as
shown in the image, the code will print two asterisks (**) to the screen, because 10 is neither less
than 0 nor greater than or equal to 42. Therefore, the correct answer is C. * *
Reference: [Python Institute - Entry-Level Python Programmer Certification]
DRAG DROP
Arrange the code boxes in the correct positions in order to obtain a loop which executes its body with
the level variable going through values 5, 1, and 1 (in the same order).
Explanation:
What happens when the user runs the following code?
D
Explanation:
The code snippet that you have sent is a while loop with an if statement and a print statement inside
it. The code is as follows:
while True: if counter < 0: print(““) else: print(”**”)
The code starts with entering a while loop that repeats indefinitely, because the condition “True” is
always true. Inside the loop, the code checks if the value of “counter” is less than 0. If yes, it prints a
single asterisk () to the screen. If no, it prints three asterisks (**) to the screen. However, the code
does not change the value of “counter” inside the loop, so the same condition is checked over and
over again. The loop never ends, and the code enters an infinite loop.
The program outputs either one asterisk () or three asterisks (**) to the screen repeatedly,
depending on the initial value of “counter”. Therefore, the correct answer is D. The program enters
an infinite loop.
Reference: [Python Institute - Entry-Level Python Programmer Certification]
What is the expected output of the following code?
C
Explanation:
The code snippet that you have sent is checking if two numbers are equal and printing the result.
The code is as follows:
num1 = 1 num2 = 2 if num1 == num2: print(4) else: print(1)
The code starts with assigning the values 1 and 2 to the variables “num1” and “num2” respectively.
Then, it enters an if statement that compares the values of “num1” and “num2” using the equality
operator (==). If the values are equal, the code prints 4 to the screen. If the values are not equal, the
code prints 1 to the screen.
The expected output of the code is 1, because the values of “num1” and “num2” are not equal.
Therefore, the correct answer is C. 1.
Reference: [Python Institute - Entry-Level Python Programmer Certification]
DRAG DROP
Arrange the code boxes in the correct positions to form a conditional instruction which guarantees
that a certain statement is executed when the speed variable is less than 50.0.
Explanation:
One possible way to arrange the code boxes in the correct positions to form a conditional instruction
which guarantees that a certain statement is executed when the speed variable is less than 50.0 is:
if speed < 50.0:
print("The speed is low.")
This code uses the if keyword to create a conditional statement that checks the value of the variable
speed. If the value is less than 50.0, then the code will print “The speed is low.” to the screen. The
print function is used to display the output. The code is indented to show the block of code that
belongs to the if condition.
You can find more information about the if statement and the print function in Python in the
following references:
Python If … Else
Python Print Function