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:
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.