Tuples Output#

  • Find the output of the following code.

  • Please don’t run the code before giving your answer.     

Question-1#

x = ('a', 'b','c',1,2,3,'a')

print(x.count('a'))
print(x.count('c'))
print(x.count('B'))

Solution

2
1
0

Question-2#


x = ('a', 'b','c',1,2,3,'a')

print(x.index('a'))
print(x.index('c'))

Solution

0
2

Question-3#


x = ('table', 'chair', 'desk','bookcase')

for i in x:
  print(x[-2])

Solution

desk
desk
desk
desk

Question-4#


x = ('table', 'chair', 'desk','bookcase')

for i in x:
  print(i[-2])

Solution

l
i
s
s

Question-5#

x = ('A', 'B', 'C')

for i in range(len(x)):
  print(i)

Solution

0
1
2

Question-6#

x = ('A', 'B', 'C')

for i in range(len(x)):
  print(x[i])

Solution

A
B
C

Question-7#


x = (12,5,3,99,123,10)

for i in x:
    if i>20:
        print(i)

Solution

99
123

Question-8#

x = (12,5,3,99,123,10)

for i in x:
    if i>20:
        if i<100:
            print(i)

Solution

99

Question-9#

n = 0
my_tuple = ('A', 'B', 'C', 'D', 'E', 'F')

for i in my_tuple:
    n += 1

print(n)

Solution

6

Question-10#


total = 0

for i in (10, 20, 30, 40):
    total += i/5

print(total)

Solution

20.0

Question-11#


total = 0

for i in (10, 20, 30, 40):
    total += i//8

print(total)

Solution

11

Question-12#

total = 0

for i in (10, 20, 30, 40):
    total += i/10
    total = i
    
print(total)

Solution

40