Computer Science
Write a program to multiply an element by 2 if it is an odd index for a given list containing both numbers and strings.
Answer
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']
Related Questions
Write a program to calculate the minimum element of a given list of numbers.
Write a code to calculate and display total marks and percentage of a student from a given list storing the marks of a student.
Write a program to count the frequency of a given element in a list of numbers.
Write a program rotates the elements of a list so that the element at the first index moves to the second index, the element in the second index moves to the third index, etc., and the element in the last index moves to the first index.