Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python error
#1
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!
Reply
#2
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)}")
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020