嵌套字典定义中的语法错误

2024-06-26 09:43:35 发布

您现在位置: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'
           } 
     *  }

Tags: orthetonotextyoujohnlike
1条回答
网友
1楼 · 发布于 2024-06-26 09:43:35

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

  {'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也能做到

相关问题 更多 >