Question Detail

COS 102 6 lecture note; fundamentals of programming Objective Question

Question

The Python code snippet is executed:
s1 = {10,20,30}
s2 = {50,20,"10"}
s3 = s1.union(s2)
print(s3)
Which of the following best describes the output given the options provided in the quiz slide?
Options
A 16
B Error
C 1
D None
Correct Answer
Correct Answer

Option D is the correct answer.

Detailed Explanation

The union() method on sets combines all unique elements from both sets. The integer 10 and the string "10" are considered distinct elements. Therefore, s3 will contain {10, 20, 30, 50, "10"}. Printing this set will display these elements. Since the options A, B, and C do not represent the actual set output or a direct error, 'None' (interpreted as 'None of the above specific numeric values are correct' or 'The actual output is not among A, B, C') is the most suitable answer from the given choices. The code itself executes without a runtime error.

Hint

Recall how Python handles different data types like integers and strings, and the behavior of set union operations. Consider what the print() function actually outputs for a set.

Question Info