GPYC Exam QuestionsBrowse all questions from this exam

GPYC Exam - Question 7


When the following program `question.py` is executed with Python what is the output?

Show Answer
Correct Answer: BC

The code provided in the image is incorrect because functions in Python are case-sensitive. The function 'i' is defined with a lowercase 'i', but the call is made to 'I' with an uppercase 'I', which is not defined. This results in a NameError, indicating that 'I' is not defined. Therefore, the error can be described as a function override issue where the function 'i' is assigned but not called correctly.

Discussion

3 comments
Sign in to comment
AZIrvThoOption: C
Sep 29, 2023

When the code is written correctly: def i (i): i=5 return i i = i (10) print(i) The response is 5, but in the exam question, the code is written incorrectly. So, shouldn't the answer be "C" noting that "i" cannot be called because of the syntax error?

natynat60Option: B
Oct 11, 2022

I is not defined. So it is an error (NameError: name 'I' is not defined) and I think it should be: def i(i): i=5 return i i=i(10) print(i) 5 #and yes the result is 5

VenudharOption: B
Nov 18, 2023

The option is B