Dec-07-2019, 04:40 PM
Hi,
Iam very sorry. i have very very basic doubt. i wrote the code and getting error. but i can't understand why error is occurring.
given list: num = [2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
Required Output = [2,3,4,5,6,12,13,14,15,16]
Raj Kumar
Iam very sorry. i have very very basic doubt. i wrote the code and getting error. but i can't understand why error is occurring.
given list: num = [2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
Required Output = [2,3,4,5,6,12,13,14,15,16]
for i in range(len(num)+1): if i<5: k.append(num[i]) elif i>len(num)-5: k.append(num[i]) else: continue print(k)Error is:
Error:---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-220-bb56973675c6> in <module>
12 k.append(s[i])
13 elif i>len(s)-5:
---> 14 k.append(s[i])
15 else:
16 continue
IndexError: list index out of range
RegardsRaj Kumar