Answer to Question #333107 in Python for Rajesh

Question #333107

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

1
Expert's answer
2022-04-24T17:16:08-0400


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)

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