Saturday, 22 September 2018

11-C Prog-26 Write a algorithm and python program accessing elements in a list(array) one by one if element even no. multiply by 10 and odd numbers divide by 5



def e_o(n):    #called function
    l=[]     # empty list
    for i in range(n):
        num=int(input("enter the number:"))
        l.append(num)

    for j in range(n):
        if l[j]%2==0:
            l[j]=l[j]*10
        else:
            l[j]=l[j]//5

    print("updated list elements=",l)

#main program
n=int(input("enter n value:"))
print("the n value is=",n)
e_o(n)   #calling function

Example:
enter n value:4
the n value is= 4
enter the number:12 enter the number:15 enter the number:20 enter the number:25
updated list elements= [120, 3, 200, 5]

No comments:

Post a Comment