Limited-Time Offer: Enjoy 50% Savings! - Ends In 0d 00h 00m 00s Coupon code: 50OFF
Welcome to QA4Exam
Logo

- Trusted Worldwide Questions & Answers

Most Recent Python Institute PCEP-30-02 Exam Dumps

 

Prepare for the Python Institute PCEP - Certified Entry-Level Python Programmer exam with our extensive collection of questions and answers. These practice Q&A are updated according to the latest syllabus, providing you with the tools needed to review and test your knowledge.

QA4Exam focus on the latest syllabus and exam objectives, our practice Q&A are designed to help you identify key topics and solidify your understanding. By focusing on the core curriculum, These Questions & Answers helps you cover all the essential topics, ensuring you're well-prepared for every section of the exam. Each question comes with a detailed explanation, offering valuable insights and helping you to learn from your mistakes. Whether you're looking to assess your progress or dive deeper into complex topics, our updated Q&A will provide the support you need to confidently approach the Python Institute PCEP-30-02 exam and achieve success.

The questions for PCEP-30-02 were last updated on May 4, 2025.
  • Viewing page 1 out of 6 pages.
  • Viewing questions 1-5 out of 30 questions
Get All 30 Questions & Answers
Question No. 1

What is the expected result of the following code?

Show Answer Hide Answer
Correct Answer: A

The code snippet that you have sent is trying to use the global keyword to access and modify a global variable inside a function. The code is as follows:

speed = 10 def velocity(): global speed speed = speed + 10 return speed

print(velocity())

The code starts with creating a global variable called ''speed'' and assigning it the value 10. A global variable is a variable that is defined outside any function and can be accessed by any part of the code. Then, the code defines a function called ''velocity'' that takes no parameters and returns the value of ''speed'' after adding 10 to it. Inside the function, the code uses the global keyword to declare that it wants to use the global variable ''speed'', not a local one. A local variable is a variable that is defined inside a function and can only be accessed by that function. The global keyword allows the function to modify the global variable, not just read it. Then, the code adds 10 to the value of ''speed'' and returns it. Finally, the code calls the function ''velocity'' and prints the result.

However, the code has a problem. The problem is that the code uses the global keyword inside the function, but not outside. The global keyword is only needed when you want to modify a global variable inside a function, not when you want to create or access it outside a function. If you use the global keyword outside a function, you will get a SyntaxError exception, which is an error that occurs when the code does not follow the rules of the Python language. The code does not handle the exception, and therefore it will terminate with an error message.

The expected result of the code is an unhandled exception, because the code uses the global keyword incorrectly. Therefore, the correct answer is A. The code is erroneous and cannot be run.


The code is erroneous because it is trying to call the ''velocity'' function without passing any parameter, which will raise aTypeErrorexception. The ''velocity'' function requires one parameter ''x'', which is used to calculate the return value of ''speed'' multiplied by ''x''. If no parameter is passed, the function will not know what value to use for ''x''.

The code is also erroneous because it is trying to use the ''new_speed'' variable before it is defined. The ''new_speed'' variable is assigned the value of 20 after the first function call, but it is used as a parameter for the second function call, which will raise aNameErrorexception. The variable should be defined before it is used in any expression or function call.

Therefore, the code will not run and will not produce any output.

The correct way to write the code would be:

# Define the speed variable

speed = 10

# Define the velocity function

def velocity(x):

return speed * x

# Define the new_speed variable

new_speed = 20

# Call the velocity function with new_speed as a parameter

print(velocity(new_speed))

Copy

This code will print 200, which is the result of 10 multiplied by 20.

[Python Programmer Certification (PCPP) -- Level 1]

[Python Programmer Certification (PCPP) -- Level 2]

[Python Programmer Certification (PCPP) -- Level 3]

[Python: Built-in Exceptions]

[Python: Defining Functions]

[Python: More on Variables and Printing]

Question No. 2

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

Show Answer Hide Answer
Correct Answer: C

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.


Question No. 3

What is true about tuples? (Select two answers.)

Show Answer Hide Answer
Correct Answer: A, D

Tuples are one of the built-in data types in Python that are used to store collections of data. Tuples have some characteristics that distinguish them from other data types, such as lists, sets, and dictionaries. Some of these characteristics are:

Tuples are immutable, which means that their contents cannot be changed during their lifetime. Once a tuple is created, it cannot be modified, added, or removed. This makes tuples more stable and reliable than mutable data types. However, this also means that tuples are less flexible and dynamic than mutable data types.For example, if you want to change an element in a tuple, you have to create a new tuple with the modified element and assign it to the same variable12

Tuples are ordered, which means that the items in a tuple have a defined order and can be accessed by using their index. The index of a tuple starts from 0 for the first item and goes up to the length of the tuple minus one for the last item. The index can also be negative, in which case it counts from the end of the tuple. For example, if you have a tuplet = ('a', 'b', 'c'), thent[0]returns'a', andt[-1]returns'c'12

Tuples can be indexed and sliced like lists, which means that you can get a single item or a sublist of a tuple by using square brackets and specifying the start and end index. For example, if you have a tuplet = ('a', 'b', 'c', 'd', 'e'), thent[2]returns'c', andt[1:4]returns('b', 'c', 'd'). Slicing does not raise any exception, even if the start or end index is out of range.It will just return an empty tuple or the closest possible sublist12

Tuples can contain any data type, such as strings, numbers, booleans, lists, sets, dictionaries, or even other tuples. Tuples can also have duplicate values, which means that the same item can appear more than once in a tuple. For example, you can have a tuplet = (1, 2, 3, 1, 2), which contains two 1s and two 2s12

Tuples are written with round brackets, which means that you have to enclose the items in a tuple with parentheses. For example, you can create a tuplet = ('a', 'b', 'c')by using round brackets. However, you can also create a tuple without using round brackets, by just separating the items with commas. For example, you can create the same tuplet = 'a', 'b', 'c'by using commas.This is called tuple packing, and it allows you to assign multiple values to a single variable12

The len() function can be applied to tuples, which means that you can get the number of items in a tuple by using the len() function. For example, if you have a tuplet = ('a', 'b', 'c'), thenlen(t)returns 312

An empty tuple is written as (), which means that you have to use an empty pair of parentheses to create a tuple with no items. For example, you can create an empty tuplet = ()by using empty parentheses. However, if you want to create a tuple with only one item, you have to add a comma after the item, otherwise Python will not recognize it as a tuple. For example, you can create a tuple with one itemt = ('a',)by using a comma12

Therefore, the correct answers are A. Tuples are immutable, which means that their contents cannot be changed during their lifetime. and D. Tuples can be indexed and sliced like lists.


Question No. 4

What is true about exceptions and debugging? (Select two answers.)

Show Answer Hide Answer
Correct Answer: A, C

Exceptions and debugging are two important concepts in Python programming that are related to handling and preventing errors. Exceptions are errors that occur when the code cannot be executed properly, such as syntax errors, type errors, index errors, etc. Debugging is the process of finding and fixing errors in the code, using various tools and techniques. Some of the facts about exceptions and debugging are:

A tool that allows you to precisely trace program execution is called a debugger. A debugger is a program that can run another program step by step, inspect the values of variables, set breakpoints, evaluate expressions, etc. A debugger can help you find the source and cause of an error, and test possible solutions. Python has a built-in debugger module called pdb, which can be used from the command line or within the code.There are also other third-party debuggers available for Python, such as PyCharm, Visual Studio Code, etc12

If some Python code is executed without errors, this does not prove that there are no errors in it. It only means that the code did not encounter any exceptions that would stop the execution. However, the code may still have logical errors, which are errors that cause the code to produce incorrect or unexpected results. For example, if you write a function that is supposed to calculate the area of a circle, but you use the wrong formula, the code may run without errors, but it will give you the wrong answer. Logical errors are harder to detect and debug than syntax or runtime errors, because they do not generate any error messages.You have to test the code with different inputs and outputs, and compare them with the expected results34

One try-except block may contain more than one except branch. A try-except block is a way of handling exceptions in Python, by using the keywords try and except. The try block contains the code that may raise an exception, and the except block contains the code that will execute if an exception occurs. You can have multiple except blocks for different types of exceptions, or for different actions to take. For example, you can write a try-except block like this:

try: # some code that may raise an exception except ValueError: # handle the ValueError exception except ZeroDivisionError: # handle the ZeroDivisionError exception except: # handle any other exception

This way, you can customize the error handling for different situations, and provide more informative messages or alternative solutions5

The default (anonymous) except branch can be the last branch in the try-except block. The default except branch is the one that does not specify any exception type, and it will catch any exception that is not handled by the previous except branches. The default except branch can be the last branch in the try-except block, but it cannot be the first or the only branch. For example, you can write a try-except block like this:

try: # some code that may raise an exception except ValueError: # handle the ValueError exception except: # handle any other exception

This is a valid try-except block, and the default except branch will be the last branch. However, you cannot write a try-except block like this:

try: # some code that may raise an exception except: # handle any exception

This is an invalid try-except block, because the default except branch is the only branch, and it will catch all exceptions, even those that are not errors, such as KeyboardInterrupt or SystemExit. This is considered a bad practice, because it may hide or ignore important exceptions that should be handled differently or propagated further.Therefore, you should always specify the exception types that you want to handle, and use the default except branch only as a last resort5

Therefore, the correct answers are A. A tool that allows you to precisely trace program execution is called a debugger. and C. One try-except block may contain more than one except branch.


Question No. 5

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

Show Answer Hide Answer
Correct Answer: B

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.


Unlock All Questions for Python Institute PCEP-30-02 Exam

Full Exam Access, Actual Exam Questions, Validated Answers, Anytime Anywhere, No Download Limits, No Practice Limits

Get All 30 Questions & Answers