Computer Science, asked by Craftsbymaha, 5 months ago

Write a python program that takes a list L as argument add 5 in all the odd values and 10 in the even values of the list L. Also display the list eg:-

the list contains:
L=[10,20,3,100,65,87,2]
Output:
L=[20,30,8,110,20,92,12]

pls give me a correct ans..don't post unnecessary things..it's a request​

Answers

Answered by Mister360
13

Answer:

Code:-

a=[]

n=int(input("Enter number of elements:"))

for i in range(1,n+1):

b=int(input("Enter element:"))

a.append(b)

even=[]

odd=[]

for j in a:

if(j%2==0):

even.append(j)

else:

odd.append(j)

print("The even list",even)

print("The odd list",odd)

code explanation:-

  • Programmer must enter the number of elements and store it in a variable.
  • programmmer must then enter the elements of the list one by one using a for loop and store it in a list.
  • Another for loop is used to traverse through the elements of the list.
  • The if statement checks if the element is even or odd and appends them to separate lists.
  • Both the lists are printed.

Runtime test:-

Case 1:-

Enter number of elements:5

Enter element:67

Enter element:43

Enter element:44

Enter element:22

Enter element:455

The even list [44, 22]

The odd list [67, 43, 455]

Case 2:

Enter number of elements:3

Enter element:23

Enter element:44

Enter element:99

The even list [44]

The odd list [23, 99]

Answered by Anonymous
7

Answer:

hope it's help full for u

Attachments:
Similar questions