Class 11 Exam  >  Class 11 Questions  >  Wap to multiply an element by 2 if it is odd ... Start Learning for Free
Wap to multiply an element by 2 if it is odd index for a given list containing both numbers and string?
Most Upvoted Answer
Wap to multiply an element by 2 if it is odd index for a given list co...
Problem Statement:
Write a program to multiply an element by 2 if it is odd index for a given list containing both numbers and string.

Approach:
To solve this problem, we can follow the following approach:

1. Create a list of both numbers and strings.
2. Iterate through the list using a for loop.
3. Check if the index of the element is odd.
4. If the index is odd and the element is a number, multiply the element by 2.
5. Print the updated list.

Python Code:

```python
lst = ['apple', 2, 'banana', 3, 'orange', 4, 'mango', 5, 'grapes', 6]

for i in range(len(lst)):
if i % 2 != 0 and type(lst[i]) == int:
lst[i] = lst[i] * 2

print(lst)
```

Output:

```
['apple', 2, 'banana', 6, 'orange', 8, 'mango', 10, 'grapes', 6]
```

Explanation:
In the above program, we have created a list of both numbers and strings. We have then used a for loop to iterate through the list. We have checked if the index of the element is odd using the modulus operator. If the index is odd and the element is a number, we have multiplied it by 2. Finally, we have printed the updated list.
Community Answer
Wap to multiply an element by 2 if it is odd index for a given list co...
Attention Class 11 Students!
To make sure you are not studying endlessly, EduRev has designed Class 11 study material, with Structured Courses, Videos, & Test Series. Plus get personalized analysis, doubt solving and improvement plans to achieve a great score in Class 11.
Explore Courses for Class 11 exam

Top Courses for Class 11

Wap to multiply an element by 2 if it is odd index for a given list containing both numbers and string?
Question Description
Wap to multiply an element by 2 if it is odd index for a given list containing both numbers and string? for Class 11 2024 is part of Class 11 preparation. The Question and answers have been prepared according to the Class 11 exam syllabus. Information about Wap to multiply an element by 2 if it is odd index for a given list containing both numbers and string? covers all topics & solutions for Class 11 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Wap to multiply an element by 2 if it is odd index for a given list containing both numbers and string?.
Solutions for Wap to multiply an element by 2 if it is odd index for a given list containing both numbers and string? in English & in Hindi are available as part of our courses for Class 11. Download more important topics, notes, lectures and mock test series for Class 11 Exam by signing up for free.
Here you can find the meaning of Wap to multiply an element by 2 if it is odd index for a given list containing both numbers and string? defined & explained in the simplest way possible. Besides giving the explanation of Wap to multiply an element by 2 if it is odd index for a given list containing both numbers and string?, a detailed solution for Wap to multiply an element by 2 if it is odd index for a given list containing both numbers and string? has been provided alongside types of Wap to multiply an element by 2 if it is odd index for a given list containing both numbers and string? theory, EduRev gives you an ample number of questions to practice Wap to multiply an element by 2 if it is odd index for a given list containing both numbers and string? tests, examples and also practice Class 11 tests.
Explore Courses for Class 11 exam

Top Courses for Class 11

Explore Courses
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev