Computer Science, asked by itsneeraj, 9 months ago

5. What will be the output of the following code snippet ?
Tup1 = ((1, 2),) * 7
print(len(Tup1 (3:8]))​

Answers

Answered by poojan
10

Answer:

4

Explanation:

Line 1 indicates that the tuple within the tuple will be 7 times written within.

So, the line stores ((1, 2), (1, 2), (1, 2), (1, 2), (1, 2), (1, 2), (1, 2)) in Tup1.

The indexing starts from 0. As the Tup1 contains 7 elements, the indexing will be 0 to 6.

(You have given Tup1(3:8]; it should be Tup1[3:8] as per slicing syntax)

On slicing, Tup1[3:8] gives ((1, 2), (1, 2), (1, 2), (1, 2)) from 0 to outer bound 6 (as the range mentioned is upto 8)

so, print(len(Tup1 [3:8]))​ gives 4 (as ((1, 2), (1, 2), (1, 2), (1, 2)) tuple contains 4 elements)

Attachments:
Answered by AskewTronics
0

Syntax error :

Explanation:

  • The above print statement has a syntax error and that is a bracket error, The statement holds an open bracket as a small bracket and the close bracket as a large bracket.
  • So there is a need to put the print statement "print(len(Tup1[3:8]))" and then the code will be executed.
  • Then the output will be rendered as 4 because the "3:8" will print the list from the index 3 to index 7 (but it will be print up to 6 index because the last index of the list is 6) which is 4 and the len function print the length which is 4.

Learn More:

  • Python : https://brainly.in/question/14689905
Similar questions