Practice Free PCEP-30-02 Exam Online Questions
Question #51
Consider the following code.

Which of the following expressions will evaluate to 19?
- A . data.r fi nd(‘an’) if data else None
- B . 19 if None else x / y
- C . data. fi nd(‘an’) if data else None
- D . 7 if len(data) > 19 else 6
Correct Answer: C
Question #52
What is the expected output of the following code?

- A . 22
- B . 6
- C . 15
- D . 14
Correct Answer: C
Question #53
What is the expected output of the following code?

- A . None
- B . 2
- C . The code is erroneous.
- D . 4
Correct Answer: C
Question #54
What will be the output of the following code snippet?

- A . 3
- B . 2
- C . 4
- D . 1
Correct Answer: C
Question #55
A variable de fi ned outside a function:
- A . may be read, but not written (something more is needed to do so)
- B . may not be accessed in any way inside the function
- C . may be freely accessed inside the function
Correct Answer: A
Question #56
What is the output of the following snippet?
![]()
- A . -2
- B . 3
- C . -1
- D . 1
Correct Answer: D
Question #57
What is the expected output of the following code?

- A . 1 | True
2 | True
3 | False
4 | False - B . 1 | True
2 | False
3 | False
4 | False - C . 1 | True
2 | False
3 | False
4 | True - D . 1 | True
2 | False
3 | True
4 | False
Correct Answer: B
Question #58
What is true about exceptions and debugging? (Select two answers.)
- A . A tool that allows you to precisely trace program execution is called a debugger.
- B . If some Python code is executed without errors, this proves that there are no errors in it.
- C . One try-except block may contain more than one except branch.
- D . The default (anonymous) except branch cannot be the last branch in the try-except block.
Correct Answer: A, C
A, C
Explanation:
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, C
Explanation:
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
Question #59
You want to write a program that asks the user for a value. For the rest of the program you need a whole number, even if the user enters a decimal value.
What would you have to write?
- A . num = str(input(‘How many do you need?’))
- B . num = int( oat(input(‘How many do you need?’)))
- C . num = oat(input(‘How many do you need?’))
- D . num = int(‘How many do you need?’)
Correct Answer: B
Question #60
DRAG DROP
Drag and drop the literals to match their data type names.

Correct Answer:


