N
N
Nomko2021-07-23 16:30:47
Python
Nomko, 2021-07-23 16:30:47

What is the reason for the error?

I'm new to this area, and I can't understand, the error appears at the moment "min = a[0]"
File "d:/Py/test.py", line 3, in
min = a[0]
IndexError: list index out of range

a=[]
index = 0
min = a[0]
for i in xrange(0,num):
    a.append(i)
    if a[i]< min:
         min = a[1]
         index = 1
print min
print index

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dmshar, 2021-07-23
@dmshar

I wonder in what "this area" is meant. If programming in the Python language, then the question arises: Has the beginner even opened a book on Python? If I opened it, even a beginner would understand that here:
a=[]
an EMPTY list is being created, and here: an attempt is made to read something from this EMPTY list. This is somehow "not very", in whatever area you would not specialize. By the way, I can assume that the next question "new to the field" will be first Why is there an error associated with xrange(0,num) , and then "why do I have an error in the lines: print min print index" Let's wait.
= a[0]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question