Python显示invalid syntax?

importrandomcapitals={'Shanxi':'TaiYuan','Shaanxi':'XiAn','HeBei':'ShiJiaZhuang','Jia... import randomcapitals={'Shanxi':'TaiYuan','Shaanxi':'XiAn','HeBei':'ShiJiaZhuang','JiangXi':'NanChang','HuBei':'WuHan','HuNan':'ChangSha','JiangSu':'NanJing','ZheJiang':'HangZhou'}for cityNum in range(6): cityFile=open('capitalscity%s.txt'%(cityNum+1),'w') answerKeyFile=open('capitalscity_answer%s.txt'%(cityNum+1),'w') cityFile.write('Name:\n\nDate:\n\nPeriod:\n\n') cityFile.write((' '*20)+'Province Capitals City(Form %s)'%(cityNum+1)) cityFile.write('\n\n') province=list(capitals.keys()) random.shuffle(province) for questionNum in range(8): correctAnswer=capitals[province[questionNum]] wrongAnswers=list(capitals.values()) del wrongAnswers[wrongAnswers.index(correctAnswer)] wrongAnswers=random.sample(wrongAnswers,3) answerOptions=wrongAnswers+[correctAnswer] random.shuffle(answerOptions) #for questionNum in range(8): cityFile.write('%s.What is the capital of %s?\n'%(questionNum+1,province[questionNum])) for i in range(4): cityFile.write(' %s. %s\n'%('ABCD'[i],answerOptions[i])) cityFile.write('\n') answerKeyFile.write('%s. %s\n'%(questionNum+1,'ABCD'[answerOptions.index(correctAnswer)]) cityFile.close() answerKeyFile.close() 展开
 我来答
CJJohn
2020-02-04 · Persistence is harder than eff...
CJJohn
采纳数:475 获赞数:1362

向TA提问 私信TA
展开全部
一般是缩进不对或者你忘了一些括号什么的
追问

源代码是这个,能看看吗

已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式