简体   繁体   中英

I keep getting SyntaxError and I don't know why

This is my code:

29 for i, j in enumerate(self.noun):
30      if j in self.c:
31          try:
32              k = j + self.noun[i + 1]
33              if k in c:
34                  self.letters.append(k)
35                  if k in self.unp:
36                      self.letstat.append("CN")
37                  elif k in self.pr:
38                      self.letstat.append("CP")
39                  else:
40                      self.letstat.append("CA")
41                      
42          self.letters.append(j)
43          if j in self.unp:
44              self.letstat.append("CN")
45          elif j in self.pr:
46              self.letstat.append("CP")
47          else:
48              self.letstat.append("CA")
49      else:
50          try:
51              if j == "i" and self.noun[i - 1] in self.pr:
52                  continue
53          self.letters.append(j)
54          self.letstat.append("V")

I keep getting this error:

Traceback (most recent call last):                                                                                        
File "C:\Users\User\Documents\programming\Python\yisib\main.py", line 1, in <module>                                      
from nouns import Noundec                                                                                             
File "C:\Users\User\Documents\programming\Python\yisib\nouns.py", line 42                                                 
self.letters.append(j)                                                                                                  
^                                                                                                                   
SyntaxError: invalid syntax

Can someone please tell me what i did wrong? I've checked the code 7 times, and i don't seem to have missed any bracket or indent. Thanks

You need some except or finally when using try :

try:
    if j == "i" and self.noun[i - 1] in self.pr:
        continue
except IndexError:
    pass

self.letters.append(j)

Question is: why? Are you expecting an IndexError ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM