a.Define a list L1 consisting of at least 10 integers (e.g. L1 =[5, -34, 0, 98, -11, 244, 193, 98, -10, -20, 45, 67])and printL1.
b.Ask the user to enter aninteger n. You may assume the userwill enter a valid input.
c.Check how many times the integernoccurs in L1.
d.If noccursat least once in L1:i.Print the index of the firstoccurrence of ninL1 with a suitable message.
ii.Print all elements if L1 afterthe first occurrence of n, witha suitable message.
iii.Remove the first occurrence of n from L1 and print theupdated list with a suitable messagee.
Otherwise(i.e. ndoes not occur in L1), print a suitablemessage.
can you help with removing the first occurrence of n from thelist. my code is below and n remains in the list when it is printedagain. please write in python.
#creates the list L1=[5, -34, 0, 98, -11, 244, 193, 98, -10, -20, 45, 67]#prints the list print (L1)
#asks for user inputn=int(input('Enter an integer: '))
#This counts the intergerscount = 0for i in range (len(L1)):#increases the count if L1 == n : loc=i count = count+1
#prints the intergers after the users inputed intergerif count>=1: for i in range(loc+1, len(L1)): print(L1)
#creates new list without the users interger L1.pop(loc) print("\nthe new list is: ", L1)
#if the user did not input an interger from the list, print thismessage.else: print("Interger",n,"is not in the list")
a.Define a list L1 consisting of at least 10 integers (e.g. L1 = [5, -34, 0, 98, -11, 244, 193, 98, -10, -20, 45, 67])an
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am