Python Forum
Computational linguistic program - Need some help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Computational linguistic program - Need some help
#3
Here is the code :
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 Huh

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
Reply


Messages In This Thread
RE: Computational linguistic program - Need some help - by Antoine - May-01-2019, 03:43 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Advanced Algorithms and Computational Models hafedh 4 2,367 Aug-31-2020, 06:37 PM
Last Post: buran

Forum Jump:

User Panel Messages

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