Write a (PYTHON) program to find and change all even numbers in a list by adding 2 and all odd numbers
by subtracting 2. ( L=[2, 5, 12, 14, 23, 45] )
Answers
Answered by
7
Answer:
This is the required python program for the question.
L=[2, 5, 12, 14, 23, 45]
print("List Before: ",L)
for i in range(len(L)):
if L[i]%2==0:
L[i]+=2
else:
L[i]-=2
print("List After: ",L)
Algorithm:
- START.
- Initialise L=[2, 5, 12, 14, 23, 45]
- Iterate a loop through the list.
- Check if the list element is odd or not. If odd, subtract 2 or else, add 2.
- Display the list.
- STOP.
See the attachment for output ☑.
Attachments:
![](https://hi-static.z-dn.net/files/d8c/db98e055d3068cc5d56c0a76ccc859aa.jpg)
Answered by
1
Attachments:
![](https://hi-static.z-dn.net/files/d82/1a28008046e2b26dd8887610ccb1e1d1.png)
![](https://hi-static.z-dn.net/files/d08/f9101daf596eb8c6d5f0794452315bd5.png)
![](https://hi-static.z-dn.net/files/d1c/5ae11b666e6a3c1393e2fff744eeaeca.png)
Similar questions