来自 电脑系统 2019-12-23 07:03 的文章
当前位置: 金沙澳门官网网址 > 电脑系统 > 正文

【金沙澳门官网网址】请问怎么改啊

金沙澳门官网网址 ,其三层循环foriinrange(4):那生机勃勃行老是报语法错误,笔者把富有tab缩进改成七个空格仍然有错,请问怎么改能让她通过啊???

#!python3#-*-coding:utf-8-*-fromrandomimport*capitals={'Alabama':'Montgomery','Alaska':'Juneau','Arizona':'Phoenix','Arkansas':'LittleRock','California':'Sacramento','Colorado':'Denver','Connecticut':'Hartford','Delaware':'Dover','Florida':'Tallahassee','Georgia':'Atlanta','Hawaii':'Honolulu','Idaho':'Boise','Illinois':'Springfield','Indiana':'Indianapolis','Iowa':'DesMoines','Kansas':'Topeka','Kentucky':'Frankfort','Louisiana':'BatonRouge','Maine':'Augusta','Maryland':'Annapolis','Massachusetts':'Boston','Michigan':'Lansing','Minnesota':'SaintPaul','Mississippi':'Jackson','Missouri':'JeffersonCity','Montana':'Helena','Nebraska':'Lincoln','Nevada':'CarsonCity','NewHampshire':'Concord','NewJersey':'Trenton','NewMexico':'SantaFe','NewYork':'Albany','NorthCarolina':'Raleigh','NorthDakota':'Bismarck','Ohio':'Columbus','Oklahoma':'OklahomaCity','Oregon':'Salem','Pennsylvania':'Harrisburg','RhodeIsland':'Providence','SouthCarolina':'Columbia','SouthDakota':'Pierre','Tennessee':'Nashville','Texas':'Austin','Utah':'SaltLakeCity','Vermont':'Montpelier','Virginia':'Richmond','Washington':'Olympia','WestVirginia':'Charleston','Wisconsin':'Madison','Wyoming':'Cheyenne'}forquiznuminrange(35):quizfile=open('capitalsquiz%s.txt'%(quiznum+1),'w')answerkeyfile=open('capitalsquiz_answer%s.txt'%(quiznum+1),'w')quizfile.write('Name:nnDate:nnPeriod:nn')quizfile.write((''*20)+'StateCapitalQuiz(Form%s)nn'%(quiznum+1),'w')states=list(capital.ksys())random.shuffle(states)#将列表states乱序forquestionnuminrange(50):#为每份试卷创建50道题correctanswer=capital[states[questionnum]]#每份试卷都将states随机化了,所以每份试卷问题顺序不同wronganswers=list(capital.values())delwronganswer[wronganswers.index(correctanswer)]#删去正确答案.index得到下标wronganswers=random.sample(wronganswers,3)#随机选出了三个错误选项answeroptions=wronganswers+[correctanswer]random.shuffle(answeroptions)#上面创建出了选项列表,选项中有一个是正确的#下面就要将创建好的问题和选项写入文件了quizfile.write('%s.whatisthecapitalof%s?n'%(questionnum+1,states[questionnum])#问题#下面打印选项#有四个选项,之前已经随机化过了,这里只需要遍历写出来就行了foriinrange(4):quizfile.write('%s.%sn'%('ABCD'[i],answeroptions[i]))#写答案文件answerkeyfile.write('%s.%sn'%(questionnum+1,'ABCD'[answeroption.index(correctanswer)]quizfile.close()answerfile.close()

本文由金沙澳门官网网址发布于电脑系统,转载请注明出处:【金沙澳门官网网址】请问怎么改啊

关键词: