Python Forum
Python error - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Python error (/thread-24438.html)



Python error - SamAnw - Feb-14-2020

Hello everyone!

I've been working on this program:
txt = "Prob03.in.txt"
msg = open(txt, "r")
msg = msg.read()
n=int
countCase=1
for prob in msg:
    prob =prob.split()
    i =0
    while i<2:
        prob[i] = int(prob[i])
        i=+1
    if prob[0] != prob[1]:
        print("false")
    elif prob[0] == prob[1]:
        print("true")

My txt file looks like this:

2
true false
true true

The output says:Traceback (most recent call last):
File "C:/Users/admin/Desktop/Prog compétition/Prob3file.py", line 10, in <module>
prob[i] = int(prob[i])
IndexError: list index out of range

I don't understand why it's not working :/

Thankyou!


RE: Python error - Larz60+ - Feb-14-2020

Quote:The output says:Traceback (most recent call last):
This is not the complete traceback.
Always post the complete unaltered traceback. It contains very valuable information.
also, please attach a sampling of Prob03.in.txt, or if small, the entire file.
the error you are getting indicates that prob dosen't contain what you think it does.

use print, it's your friend,
for example after line 7, add:
print(f"len(prob): {len(prob)}")