CBSE Class 11 Informatics Practices Question 66 of 80

Lists in Python — Question 29

Back to all questions
29
Question

Question 24

WAP to multiply an element by 2 if it is 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