嵌套字典定义中的SyntaxError

时间:2017-04-18 01:02:05

标签: python

我一直在制作这个游戏一段时间,但我一直有这个反复出现的问题。由于某种原因,第一个括号没有标记最后一个括号,使其无法运行。有人解决了这个问题吗?语法错误位于最后一行,我在其中放置了一个星号*,以便于查找。

game = {'Room 1':
           {'occupant': 'Narrator',
            'option': 
               {'text': 'Do you want to start? (Yes or No)',
               'Yes': 'Milwaukee',
               'No': 'Dumpsterr'
               }
       },
     {'Milwaukee':
       {'occupant': 'Giannis',
        'option': 
           {'text': 'Do you want to go hit the weight room?(Yes or No)',
           'Yes': 'Weight Room',
           'No': 'Dumpster'
           }                
       },           
     {'Weight Room':
       {'occupant': 'Giannis',
        'option': 
           {'text': 'Lets get started (Yes or No)',
           'Yes': 'Giannis Thanksgiving party',
           'No': 'Dumpster'
           }                
       },
      {'John Hammond':
       {'occupant': 'John Hammond',
        'option': 
           {'text': 'Hey your taking up my valuabe XBOX time. Intrested in this team yes or no?(Yes or No)',
           'Yes': 'Draft',
           'No': 'Undrafted'
           } 
       },
      {'John Hammond house':
       {'occupant': 'John Hammond wife',
        'option': 
           {'text': 'Welcome to the Hammond house hold! Hi honey would you like some cookies? -  Mrs.Hammond(Yes or No)',
           'Yes': 'Draft Day',
           'No': 'How Dare You'
           } 
       },
      {'Draft Day':
       {'occupant': 'Adam Silver',
        'option': 
           {'text': 'Welcome to the NBA draft! With the tenth overall pick you have been selected? Do you accept (Yes or No)',
           'Yes': 'Winner',
           'No': 'Undrafted'
           } 
       },
      {'Dumpster':
       {'occupant': 'Dennis Rodman',
        'option': 
           {'text': 'Welcome to the dumpster! I know im a fool. To get away you have to restart. Would you like to restart?. (Yes or No)',
           'Yes': 'Room 1',
           'No': 'Dumpster'
           }
       },
      {'How dare you':
       {'occupant': 'John Hammond',
        'option': 
           {'text': 'How dare you disrespect my wifes cooking you monster! Good luck now getting draft idiot. Would you like to restart? -  John Hammond(Yes or No)',
           'Yes': 'Room 1',
           'No': 'Room 1'
           } 
       },
      {'Undrafted':
       {'occupant': 'Nobody',
        'option': 
           {'text': 'You had your chance... would you like a redo? (Yes or No)',
           'Yes': 'Room 1',
           'No': 'Undrafted'
           } 
     *  }

1 个答案:

答案 0 :(得分:1)

每个数据部分都有一个未闭合的大括号。例如:

  {'How dare you':
   {'occupant': 'John Hammond',
    'option': 
       {'text': 'How dare you disrespect my wifes cooking you monster! Good luck now getting draft idiot. Would you like to restart? -  John Hammond(Yes or No)',
       'Yes': 'Room 1',
       'No': 'Room 1'
       } 
   },
  {'Undrafted':
   {'occupant': 'Nobody',
    'option': 
       {'text': 'You had your chance... would you like a redo? (Yes or No)',
       'Yes': 'Room 1',
       'No': 'Undrafted'
       } 
 *  }

你还没有关闭“你怎么敢”或“未选择”的章节。每个都有三个左括号和两个右括号。看起来您的数据的每个部分都会遇到此问题。

顺便说一句,任何合理智能的文本编辑器都会为你提供大括号。即使 vim 也能做到。 : - )