0

n='user value',c=[ ] for i in range(n): print("Enter Column No ",i,": ") c[i]=int(input()) , it keeps giving index error

I created an empty list 'c' and now i want to fill from the user But it says index out of range! How??? c is an empty list but i can't even access the first Index which is c[0]! How can that be outta range? n is a number entered by user

14th Sep 2021, 3:02 AM
Farzam Baig
5 odpowiedzi
+ 2
Is n='user value' supposed to be an integer entered by the user or is it the actual string as is? If so your loop won't work. Try using; c.append(int(input())) instead of c[i]=int(input()) Since c=[] has no length c[i] will result in an index error.
14th Sep 2021, 3:08 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
Farzam Baig it's usually best to just leave your actual code so as not to confuse us (a bunch of programmers who read code literally!). The less we have to infer the better. Otherwise, if doing so make a note, unless it is a common practice, such as leaving an ellipsis (...) to indicate where code would go in a shorthand form of an example. Anyway, see my previous post. It should solve your problem.
14th Sep 2021, 3:23 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Okay then u have to give n = int(input()) Instead of n = ' user value'
14th Sep 2021, 3:11 AM
Pariket Thakur
Pariket Thakur - avatar
0
HrCoder no n is a number entered by the user Not a string
14th Sep 2021, 3:10 AM
Farzam Baig
0
HrCoder obviously I've done that I said User value to let the ppl understand
14th Sep 2021, 3:12 AM
Farzam Baig