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


Messages In This Thread
Python error - by SamAnw - Feb-14-2020, 04:59 AM
RE: Python error - by Larz60+ - Feb-14-2020, 07:20 AM

Forum Jump:

User Panel Messages

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