Question Detail

COS 102 6 lecture note; fundamentals of programming Objective Question

Question

Based on the provided Python quizzes (page 12), what would be the output or outcome of the following code snippet if run in a Python 3 environment?
sum = lambda a,b : a+b
print (sum(5,6))
print sum(10,30)
Options
A 11, 50
B 11, 40
C Error
Correct Answer
D None of the above
Correct Answer

Option C is the correct answer.

Detailed Explanation

In Python 3, print is a function and requires parentheses. The line print sum(10,30) uses Python 2 syntax for the print statement, which would result in a Syntax Error in Python 3. The first line print (sum(5,6)) would correctly output 11.

Hint

Pay close attention to Python's version-specific syntax, especially for built-in functions.

Question Info