In: Computer Science
This is a short but tricky program that uses multiple variables and tuple assignment. Fill in the blanks such that the output is "10".
a = ((2,4), (1, 6)) b, (c, d) = a e = ____ + ____ [ ____ ] print(e) # Should print "10"
First blank: [ Select ] ["c", "b", "e", "d", "a"]
Second blank: [ Select ] ["b", "a", "d", "c", "e"]
Third blank:
This is simple if you see the above lines of code one by one:
a = ((2,4), (1, 6))
It assigns two lists elements- (2,4) and (1,6) to the variable a.
b, (c, d) = a
This line makes some reassignments. As can be seen with one to one correspondence. the element b will now be equals to (2,4) and (c,d) will be equals to (1,6). So, c=1 and d=6.
So, In order to print 10, you need to have e=10 which can be obtained using e=6+4. Utlizing the above variable assignments, this can be written as
e=d+b[1].
Thus, the answer to missing blanks are as follows:
First Blank: d
Second Blank: b
Third Blank: 1