मराठी

Write a function EOReplace() in Python, which accepts a list L of numbers. Thereafter, it increments all even numbers by 1 and decrements all odd numbers by 1. Example: If Sample Input data - Computer Science (Python)

Advertisements
Advertisements

प्रश्न

Write a function EOReplace() in Python, which accepts a list L of numbers. Thereafter, it increments all even numbers by 1 and decrements all odd numbers by 1.

Example:

If Sample Input data of the list is:

L = [10, 20, 30, 40, 35, 55]

Output will be:

L = [11, 21, 31, 41, 34, 54]
कोड लेखन
Advertisements

उत्तर

def EOReplace():
L=eval(input("Enter list of numbers :"))
print("Original list :",L)
for a in range(len(L)):
          if L[a]%2==0:
             L[a]+=1
          elif L[a]%2!=0:
             L[a]-=1
        print("Modified list :",L)
EOReplace()
shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
2022-2023 (March) Set 4
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×