Answer to Question #251454 in Python for Hilok

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.
1
Expert's answer
2021-10-16T01:38:14-0400
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)
    

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS