DumpsFiles
 Request Exam  Contact
  • Home
  • PRACTICE EXAMS
    Oracle
    Fortinet
    Juniper
    Microsoft
    Cisco
    Citrix
    CompTIA
    VMware
    SAP
    EMC
    PMI
    HP
    Salesforce
    Other
  • View All Exams
  • New Dumps Files
  • Upload
  • Oracle
    Oracle
  • Fortinet
    Fortinet
  • Juniper
    Juniper
  • Microsoft
    Microsoft
  • Cisco
    Cisco
  • Citrix
    Citrix
  • CompTIA
    CompTIA
  • VMware
    VMware
  • SAP
    SAP
  • EMC
    EMC
  • PMI
    PMI
  • HP
    HP
  • Salesforce
    Salesforce
  1. Home
  2. Python Institute
  3. PCEP - Certified Entry-Level Python Programmer
  4. PythonInstitute.PCEP-30-02.v2025-12-15.q25
  5. Question 2

Join the discussion

Question 2/25

What is the expected result of the following code?

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.
Reference: Python Global Keyword - W3SchoolsPython Exceptions: An Introduction - Real Python The code is erroneous because it is trying to call the "velocity" function without passing any parameter, which will raise a TypeError exception. 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 a NameError exception. 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.
References:
[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]

Add Comments

Your email address will not be published. Required fields are marked *

insert code
Type the characters from the picture.
Rating:
Other Question (25q)
Q1. How many hashes (+) does the code output to the screen? (Exhibit)...
Q2. What is the expected result of the following code? (Exhibit)...
Q3. What is the expected output of the following code? (Exhibit)...
Q4. Drag and drop the conditional expressions to obtain a code which outputs * to the screen. ...
Q5. Arrange the binary numeric operators in the order which reflects their priorities, where t...
Q6. What is the expected output of the following code? (Exhibit)...
Q7. What is the expected output of the following code? (Exhibit)...
Q8. What happens when the user runs the following code? (Exhibit)...
Q9. Drag and drop the literals to match their data type names. (Exhibit)...
Q10. Python Is an example of which programming language category?...
Q11. What is the expected output of the following code? (Exhibit)...
Q12. What is the expected output of the following code? (Exhibit)...
Q13. What happens when the user runs the following code? (Exhibit)...
Q14. What is true about exceptions and debugging? (Select two answers.)...
Q15. What is the expected result of the following code? (Exhibit)...
Q16. Which of the following functions can be invoked with two arguments?...
Q17. Arrange the binary numeric operators in the order which reflects their priorities, where t...
Q18. What is the expected output of the following code? (Exhibit)...
Q19. Arrange the code boxes in the correct positions to form a conditional instruction which gu...
Q20. Insert the code boxes in the correct positions in order to build a line of code which asks...
Q21. What is the expected output of the following code? (Exhibit)...
Q22. Drag and drop the literals to match their data type names. (Exhibit)...
Q23. Assuming that the phonc_dir dictionary contains namemumber pairs, arrange the code boxes t...
Q24. What happens when the user runs the following code? (Exhibit)...
Q25. Assuming that the phonc_dir dictionary contains namemumber pairs, arrange the code boxes t...
[×]

Download PDF File

Enter your email address to download PythonInstitute.PCEP-30-02.v2025-12-15.q25.pdf

Email:

DumpsFiles

Our website provides the Largest and the most Latest vendors Certification Exam materials around the world.

Using dumps we provide to Pass the Exam, we has the Valid Dumps with passing guranteed just which you need.

  • DMCA
  • About
  • Contact Us
  • Privacy Policy
  • Terms & Conditions
©2025 DumpsFiles

www.dumpsfiles.com materials do not contain actual questions and answers from Cisco's certification exams.