CBSE Class 12 Computer Science Question 71 of 120

Review of Python Basics — Question 23

Back to all questions
23
Question

Question 18

Write a program to multiply an element by 2 if it is an odd index for a given list containing both numbers and strings.

Solution
mixed = eval(input("Enter the list: "))
for index in range(1, len(mixed), 2):
        mixed[index] *= 2  
print("Modified List:", mixed)
Output
Enter the list: [1, 'apple','banana', 5, 'cherry', 7, 'date', 'cherry'] 
Modified List: [1, 'appleapple', 'banana', 10, 'cherry', 14, 'date', 'cherrycherry']
Answer