Question #251454

2. The sequence of natural numbers a1, a2, ..., an is given. Replace the terms greater than the given number Z. with this number. Calculate the number of substitutions.

Expert's answer

def substitution(list1, number):
   
    row = 0
    for i in range(0, len(list1)):
        if(int(list1[i])>number):
            list1[i] = number
            row +=  1
    print("The number of substitution   " +str(row))
    print("The new sequence is: ", format(list1))
#Testing the function   
list1 = [9,10,11,12,20,23]
substitution(list1,13)
    

LATEST TUTORIALS
APPROVED BY CLIENTS