ho =[]
for i in range(1,5) :
for j in range(1,4) :
ho[i][j] = (i*100 + j)
for i in range(1,5) :
for j in range(1,4) :
if ho[1][1] or ho[3][1] or ho[2][3] or ho[4][4] :
continue
else :
print("bottled water delivery: %d", ho[i][j])
It's a simple two-dimensional list problem. We deliver water to the villa, except for the houses written on the if, such as 101 and 301 Print it out to show delivery completion. I keep getting errors
ho[i][j] = (i*100 + j)
IndexError: list index out of range
This is an error. But it's simple to put a value in the list index I don't know why this error occurs.
Here's the code I changed after looking at the two-dimensional list in the book. Similarly, there is an error.
ho = []
ho2 = []
for i in range(1,5) :
for j in range(1,4) :
ho[j].append = (i*100 + j)
ho[i] .append(ho[j])
ho[j] = []
for i in range(1,5) :
for j in range(1,4) :
if ho[1][1] or ho[3][1] or ho[2][3] or ho[4][4] :
continue
else :
print("bottled water delivery: %d", ho[i][j])
ho[j].append = (i*100 + j)
IndexError: list index out of range
What's the reason?
python
ho = []
Not
ho = [[0]*5 for i in range(5)]
If you change it to and proceed, there will be no index error.
© 2024 OneMinuteCode. All rights reserved.