Exam4Training

Python Institute PCEP-30-02 PCEP – Certified Entry-Level Python Programmer Online Training

Question #1

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.)

Reveal Solution Hide Solution

Correct Answer:

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]


Question #2

A set of rules which defines the ways in which words can be coupled in sentences is called:

  • A . lexis
  • B . syntax
  • C . semantics
  • D . dictionary

Reveal Solution Hide Solution

Correct Answer: B
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]

Question #3

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.

Reveal Solution Hide Solution

Correct Answer:

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:


Question #3

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.

Reveal Solution Hide Solution

Correct Answer:

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:


Question #5

Which of the following expressions evaluate to a non-zero result? (Select two answers.)

  • A . 2**3/A-2
  • B . 4/2**3-2
  • C . 1**3/4-1
  • D . 1*4//2**3

Reveal Solution Hide Solution

Correct Answer: AB
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.5C.1**3/4-1=1/4-1=0.25-1=-0.75D.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]

Question #6

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.)

Reveal Solution Hide Solution

Correct Answer:

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]


Question #7

Python Is an example of which programming language category?

  • A . interpreted
  • B . assembly
  • C . compiled
  • D . machine

Reveal Solution Hide Solution

Correct Answer: A
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]

Question #8

DRAG DROP

Drag and drop the literals to match their data type names.

Reveal Solution Hide Solution

Correct Answer:

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]


Question #9

How many hashes (+) does the code output to the screen?

  • A . one
  • B . zero (the code outputs nothing)
  • C . five
  • D . three

Reveal Solution Hide Solution

Correct Answer: C
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]

Question #10

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.)

Reveal Solution Hide Solution

Correct Answer:

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]


Question #11

What happens when the user runs the following code?

  • A . The code outputs 3.
  • B . The code outputs 2.
  • C . The code enters an infinite loop.
  • D . The code outputs 1.

Reveal Solution Hide Solution

Correct Answer: B
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]

Exit mobile version