Question Detail

COS 102 6 lecture note; fundamentals of programming Objective Question

Question

Consider the Python code snippet from slide 12: sum = lambda a,b : a+b print (sum(5,6)) print sum(10,30) What is the expected output?
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

The first print (sum(5,6)) will correctly print 11. However, the second print sum(10,30) uses Python 2 syntax for the print statement without parentheses. In Python 3 (which is implied by 'Python Quiz' and the general context of modern Python education), this will cause a SyntaxError.

Hint

Consider the Python version being used. How does the print function work in modern Python (Python 3)?

Question Info