Computer Science - Class 12
Solutions to CBSE Sample Paper - Computer Science Class 12

Predict the output of the Python code given below:

tuple1 = (11, 22, 33, 44, 55 ,66)

list1 =list(tuple1)

new_list = []

for i in list1:

if i%2==0:

new_list.append(i)

new_tuple = tuple(new_list)

print(new_tuple)

 

Answer:

Question 24 (Choice 2) -Teachoo.png

Output: (22, 44, 66)

Explanation:

  • tuple1 is a tuple with 6 elements.
  • tuple1 is converted into a list and assigned to list1.
  • A new list called ‘new_list’ is created.
  • The for loop iterates through each item in list1 and checks if it is divisible by 2. If it is, then the item is appended to new_list.
  • new_list is converted into a tuple and assigned to new_tuple.
  • new_tuple is then printed.
Ask a doubt
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.