You are given on array a of n integers on which the followings operations can be performed
Pick an index i,0<= i<n.
Choose any integer p.
Replace a
import random
n=int(input('n='))
ls=list()
for i in range(n):
num=int(input('Input number: '))
ls.append(num)
sz=n
print("================== Before operation ================")
print(ls)
while sz!=0:
ind=random.randint(0,n-1)#Pick index
p=random.randint(-1000,1000)#choose p
ls[ind]=p#replace
sz-=1
print("================== After operation ================")
print(ls)
Comments
Leave a comment