时光轻浅,半夏挽歌 2021-01-24 16:35 采纳率: 0%
浏览 17
已结题

python代码 运行报错

代码 和报错 部分 如图中所示 求大神指点

import random 

amino_acid={'Alanine':'Ala','Valine':'Val','Leucine':'Leu','Isoleucine':'Ile','Phenylalanine':'Phe','Tryptophane':'Trp','Mrthionine':'Met','Proline':'Pro','Glycine':'Gly','Serine':'Ser','Threinine':'Thr','Cysteine':'Cys','Tyrosine':'Tyr','Asparagine':'Asn','Glutamine':'Gln','Histidine':'His','Lysine':'Lys','Argine':'Arg','Aspartic acid':'Asp','Glutamic acid':'Glu'}
#generate 35 quiz files.
for i in range(35):
    #create the quiz and answer key files.
    quiz_file=open('quiz%s.txt'%(i+1),'w')
    answerkey_file=open('quiz_answer%s.txt'%(i+1),'w')
    #write out the header for the quiz.
    quiz_file.write('Name:\n\nDate:\n\nPeriod:\n\n')
    quiz_file.write((' '*20)+'Amino acids quiz (Form %s)'%(i+1))
    quiz_file.write('\n\n')
    #shuffle the order of the states.
    quancheng=list(amino_acid.keys())
    random.shuffle(quancheng)
    #loop through all 20 amino acids, making a questions for each.
    for j in range(20):
        #get right and wrong answers.
        correct_answer=amino_acid[quancheng[j]]
        wrong_answer=list(amino_acid.values())
        del wrong_answer[wrong_answer.index(correct_answer)]
        answer_options=wrong_answer+[correct_answer]
        random.shuffle(answer_options)
        #write the question and the answer options to the quiz file.
        quiz_file.write('%s.What is the fullname of %s\n'%(j+1,quancheng[j]))
        for k in range(4):
            quiz_file.write(' %s. %s\n'%('ABCD'[k],answer_options[k])
        #write a answer key to a file.
        answerkey_file.write('%s. %s\n'%(j+1,'ABCD'[answer_options.index(correct_answer)]))
    quiz_file.close()
    answerkey_file.close()
  • 写回答

1条回答 默认 最新

  • sxysoft_csdn 2021-01-24 17:44
    关注
    quiz_file.write(' %s. %s\n' % ('ABCD'[k], answer_options[k]) 这句少了一个)符号修改如下:
    quiz_file.write(' %s. %s\n' % ('ABCD'[k], answer_options[k]))

    更多Python知识请参考

    http://www.xinbiancheng.cn/python3/

     

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 9月22日

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题