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
5 ответов
+ 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.
+ 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.
+ 1
Okay then u have to give
n = int(input())
Instead of
n = ' user value'
0
HrCoder no n is a number entered by the user
Not a string
0
HrCoder obviously I've done that
I said User value to let the ppl understand