At ValidExamDumps, we consistently monitor updates to the Python Institute PCEP-30-02 exam questions by Python Institute. Whenever our team identifies changes in the exam questions,exam objectives, exam focus areas or in exam requirements, We immediately update our exam questions for both PDF and online practice exams. This commitment ensures our customers always have access to the most current and accurate questions. By preparing with these actual questions, our customers can successfully pass the Python Institute PCEP - Certified Entry-Level Python Programmer exam on their first attempt without needing additional materials or study guides.
Other certification materials providers often include outdated or removed questions by Python Institute in their Python Institute PCEP-30-02 exam. These outdated questions lead to customers failing their Python Institute PCEP - Certified Entry-Level Python Programmer exam. In contrast, we ensure our questions bank includes only precise and up-to-date questions, guaranteeing their presence in your actual exam. Our main priority is your success in the Python Institute PCEP-30-02 exam, not profiting from selling obsolete exam questions in PDF or Online Practice Test.
What happens when the user runs the following code?
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.
What is the expected result of the following code?
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]
What is the expected output of the following code?
The code snippet that you have sent is defining and calling a function in Python. The code is as follows:
def runner(brand, model, year): return (brand, model, year)
print(runner(''Fermi''))
The code starts with defining a function called ''runner'' with three parameters: ''brand'', ''model'', and ''year''. The function returns a tuple with the values of the parameters. A tuple is a data type in Python that can store multiple values in an ordered and immutable way. A tuple is created by using parentheses and separating the values with commas. For example, (1, 2, 3) is a tuple with three values.
Then, the code calls the function ''runner'' with the value ''Fermi'' for the ''brand'' parameter and prints the result. However, the function expects three arguments, but only one is given. This will cause a TypeError exception, which is an error that occurs when a function or operation receives an argument that has the wrong type or number. The code does not handle the exception, and therefore it will terminate with an error message.
However, if the code had handled the exception, or if the function had used default values for the missing parameters, the expected output of the code would be ('Fermi ', '2021', 'False'). This is because the function returns a tuple with the values of the parameters, and the print function displays the tuple to the screen. Therefore, the correct answer is D. ('Fermi ', '2021', 'False').
Assuming that the following assignment has been successfully executed:
My_list -- [1, 1, 2, 3]
Select the expressions which will not raise any exception.
(Select two expressions.)
The code snippet that you have sent is assigning a list of four numbers to a variable called ''my_list''. The code is as follows:
my_list = [1, 1, 2, 3]
The code creates a list object that contains the elements 1, 1, 2, and 3, and assigns it to the variable ''my_list''. The list can be accessed by using the variable name or by using the index of the elements. The index starts from 0 for the first element and goes up to the length of the list minus one for the last element. The index can also be negative, in which case it counts from the end of the list. For example, my_list[0] returns 1, and my_list[-1] returns 3.
The code also allows some operations on the list, such as slicing, concatenation, repetition, and membership. Slicing is used to get a sublist of the original list by specifying the start and end index. For example, my_list[1:3] returns [1, 2]. Concatenation is used to join two lists together by using the + operator. For example, my_list + [4, 5] returns [1, 1, 2, 3, 4, 5]. Repetition is used to create a new list by repeating the original list a number of times by using the * operator. For example, my_list * 2 returns [1, 1, 2, 3, 1, 1, 2, 3]. Membership is used to check if an element is present in the list by using the in operator. For example, 2 in my_list returns True, and 4 in my_list returns False.
The expressions that you have given are trying to access or manipulate the list in different ways. Some of them are valid, and some of them are invalid and will raise an exception. An exception is an error that occurs when the code cannot be executed properly. The expressions are as follows:
A) my_list[-10]: This expression is trying to access the element at the index -10 of the list. However, the list only has four elements, so the index -10 is out of range. This will raise an IndexError exception and output nothing.
B) my_list|my_Li1st | 3| I: This expression is trying to perform a bitwise OR operation on the list and some other operands. The bitwise OR operation is used to compare the binary representation of two numbers and return a new number that has a 1 in each bit position where either number has a 1. For example, 3 | 1 returns 3, because 3 in binary is 11 and 1 in binary is 01, and 11 | 01 is 11. However, the bitwise OR operation cannot be applied to a list, because a list is not a number. This will raise a TypeError exception and output nothing.
C) my list [6]: This expression is trying to access the element at the index 6 of the list. However, the list only has four elements, so the index 6 is out of range. This will raise an IndexError exception and output nothing.
D) my_List- [0:1]: This expression is trying to perform a subtraction operation on the list and a sublist. The subtraction operation is used to subtract one number from another and return the difference. For example, 3 - 1 returns 2. However, the subtraction operation cannot be applied to a list, because a list is not a number. This will raise a TypeError exception and output nothing.
Only two expressions will not raise any exception. They are:
B) my_list|my_Li1st | 3| I: This expression is not a valid Python code, but it is not an expression that tries to access or manipulate the list. It is just a string of characters that has no meaning. Therefore, it will not raise any exception, but it will also not output anything.
D) my_List- [0:1]: This expression is a valid Python code that uses the slicing operation to get a sublist of the list. The slicing operation does not raise any exception, even if the start or end index is out of range. It will just return an empty list or the closest possible sublist. For example, my_list[0:10] returns [1, 1, 2, 3], and my_list[10:20] returns []. The expression my_List- [0:1] returns the sublist of the list from the index 0 to the index 1, excluding the end index. Therefore, it returns [1]. This expression will not raise any exception, and it will output [1].
Therefore, the correct answers are B. my_list|my_Li1st | 3| I and D. my_List- [0:1].
What is the expected output of the following code?
The code snippet that you have sent is using the count method to count the number of occurrences of a value in a list. The code is as follows:
my_list = [1, 2, 3, 4, 5] print(my_list.count(1))
The code starts with creating a list called ''my_list'' that contains the numbers 1, 2, 3, 4, and 5. Then, it uses the print function to display the result of calling the count method on the list with the argument 1. The count method is used to return the number of times a value appears in a list. For example, my_list.count(1) returns 1, because 1 appears once in the list.
The expected output of the code is 1, because the code prints the number of occurrences of 1 in the list. Therefore, the correct answer is D. 1.