Tuples has 9 Questions

Which of the following is a Python tuple?

[1, 2, 3]

(1, 2, 3)

{1, 2, 3}

{}

Suppose t = (1, 2, 4, 3), which of the following is incorrect?

print(t[3])

t[3] = 45

print(max(t))

print(len(t))

What will be the output?

>>>t=(1,2,4,3)

>>>t[1:3]

(1, 2)

(1, 2, 4)

(2, 4)

(2, 4, 3)

What will be the output?

>>>t=(1,2,4,3)

>>>t[1:-1]

(1, 2)

(1, 2, 4)

(2, 4)

(2, 4, 3)

What will be the output?

d = {"john":40, "peter":45}

d["john"]

40

45

"john"?

"peter"?

What will be the output?

>>>t = (1, 2)

>>>2 * t

(1, 2, 1, 2)

[1, 2, 1, 2]

(1, 1, 2, 2)

[1, 1, 2, 2]

What will be the output?

>>>my_tuple = (1, 2, 3, 4)

>>>my_tuple.append( (5, 6, 7) )

>>>print len(my_tuple)

1

2

5

Error

What will be the output?

numberGames = {}

numberGames[(1,2,4)] = 8

numberGames[(4,2,1)] = 10

numberGames[(1,2)] = 12

?

sum = 0

for k in numberGames:

sum += numberGames[k]

?

print len(numberGames) + sum

30

24

33

12

What will be the output?

numberGames = {}

numberGames[(1,2,4)] = 8

numberGames[(4,2,1)] = 10

numberGames[(1,2)] = 12

?

sum = 0

for k in numberGames:

sum += numberGames[k]

?

print len(numberGames) + sum

30

24

33

12