Here is the code :
The problem is with the while loop, which instead of stop at the last sentence, give it another turn from the beginning and then stop.
Why questions would be empty? I am pretty sure having verified with print each time and that returned things
For the error message, when the while loop is like this :
import re words=[] questions=[] text = open("dutch", mode="r") for line in text: line=line.rstrip("\n") list=re.finditer(r"\b[dD]e\b|\b[hH]et\b", line) for correspondance in list: words.append(correspondance.group(0)) list2 = re.sub(r"((\b[Hh]et\b)|(\b[Dd]e\b))", "?", line) if list2: questions.append(list2) for line in questions: i = 0 o = 0 u = 0 while i<len(questions) and o<len(words): print(questions[i]) answer = input("Which article? ") if answer == words[o]: print("Right answer") u = 0 + 1 else: print("Wrong answer") i = i + 1 o = o + 1 print ("Grade", u, "sur", i) text.close()and the sentences :
Ik heb het werk gedaan. De man is rijk.Well, there is no error messages when launch as it is here.
The problem is with the while loop, which instead of stop at the last sentence, give it another turn from the beginning and then stop.
Why questions would be empty? I am pretty sure having verified with print each time and that returned things
For the error message, when the while loop is like this :
while i<=len(questions) and o<=len(words):
Error:Traceback (most recent call last):
Wrong answer
File "/home/antoine/Programs/tao/texte_a_trou.py", line 25, in <module>
print(questions[i])
IndexError: list index out of range
Process finished with exit code 1