用python制作多份试卷防止作弊(随机排列题目顺序和答案顺序,提供参考答案)
#! /usr/bin/python
# randomQuizeGenerator.py - Creates quizzes with questions and answers in
# random order, along with the answer key.
import random
#The quize data. Keys are states and values are their capitals.
capitals = {'Alabama':'Montgomery', 'Alaska':'Juneau','Arizona':'Phoenix','Arkansas':'Little Rock', 'California':'Sacramento'}
#Generate 3 quiz files.
for quizNum in range(3):
#Create the quiz and answer key files.
quizFile = open('capitalsquiz%s.txt'%(quizNum+1),'w')
answerKeyFile = open('capitalsquiz_answers%s.txt'%(quizNum+1),'w')
#Write out the header for the quiz.
quizFile.write('Name:\n\nDate:\n\nPeriod:\n\n')
quizFile.write((' '*20)+'State Capitals Quiz (Form %s)'%(quizNum + 1))
quizFile.write('\n\n')
#Shuffle the order of the states.
states = list(capitals.keys())
random.shuffle(states)
#Loop through all 5 states, making a question for each.
for questionNum in range(5):
#Get right and wrong answers:
correctAnswer = capitals[states[questionNum]]
wrongAnswers = list(capitals.values())
del wrongAnswers[wrongAnswers.index(correctAnswer)]
wrongAnswers = random.sample(wrongAnswers, 3)
answerOptions = wrongAnswers + [correctAnswer]
random.shuffle(answerOptions)
#Write the question and answer options to the quiz file.
quizFile.write('%s.What is the capital of %s ?\n'%((questionNum+1),states[questionNum]))
for i in range(4):
# quizFile.write('%s %s \n'%(option[i])%(answerOptions[i]))
quizFile.write('%s.'%('ABCD'[i]))
quizFile.write('%s \n'%(answerOptions[i]))
quizFile.write('\n')
#TODO: Write the answer key to a file
answerKeyFile.write('%s.%s\n'%((questionNum+1),'ABCD'[answerOptions.index(correctAnswer)]))
quizFile.close()
answerKeyFile.close()
用python制作多份试卷防止作弊(随机排列题目顺序和答案顺序,提供参考答案)的更多相关文章
- 使用python制作ArcGIS插件(4)界面交互
使用python制作ArcGIS插件(4)界面交互 by 李远祥 插件界面部分,除了一开始在设计器中设计的这些界面元素之外,还可以与操作系统进行一些输入输出的交互,这部分的实现全部在pythonadd ...
- 使用python制作ArcGIS插件(5)其他技巧
使用python制作ArcGIS插件(5)其他技巧 by 李远祥 使用python做插件开发,除了了解ArcToolBox工具之外,还需要在了解ArcPy的相关函数和接口.只有掌握了这些,才可以顺利的 ...
- 使用python制作ArcGIS插件(3)ArcPy的使用说明
使用python制作ArcGIS插件(3)ArcPy的使用说明 by 李远祥 ArcPy 是一个以成功的 arcgisscripting 模块为基础并继承了 arcgisscripting 功能进而构 ...
- 使用python制作ArcGIS插件(2)代码编写
使用python制作ArcGIS插件(2)代码编写 by 李远祥 上一章节已经介绍了如何去搭建AddIn的界面,接下来要实现具体的功能,则到了具体的编程环节.由于使用的是python语言进行编程,则开 ...
- 使用python制作ArcGIS插件(1)工具介绍
使用python制作ArcGIS插件(1)工具介绍 by 李远祥 ArcGIS从10.0开始支持addin(ArcGIS软件中又叫作加载项)的方式进行插件制作.相对于以往9.x系列,addin的无论是 ...
- python制作pdf电子书
python制作pdf电子书 准备 制作电子书使用的是python的pdfkit这个库,pdfkit是 wkhtmltopdf 的Python封装包,因此在安装这个之前要安装wkhtmltopdf 安 ...
- 使用python制作时间戳转换工具
使用python制作时间戳转换工具 python 时间戳转日期 日期转时间戳 前言:作为一个程序员一般情况下,json和时间戳是常用的两个工具,我咨询过很多个朋友,他们一般都是通过在线工具对json进 ...
- python制作exe可执行文件的方法---使用pyinstaller
python制作exe可执行文件的方法---使用pyinstaller python生成windows下exe格式的可执行程序有三种可选方案: py2exe是大家所熟知的,今天要介绍pyinsta ...
- 随机生成一份试卷,试卷的种类分为单选、多选、判断三种题型。nodejs6.0 mysql
背景:从数据库中,随机生成一份试卷,试卷的种类分为单选.多选.判断三种题型. 首先我需要生成随机数id(在这之前我需要知道数据库中各个题型的题数,这样我才能设置随机数),并依据生成的随机数id,去查找 ...
随机推荐
- Java8新特性一览表
总览 forEach() method in Iterable interface(Iterable接口中的forEach()方法) default and static methods in Int ...
- gulp常用插件之pump使用
更多gulp常用插件使用请访问:gulp常用插件汇总 pump这是一款小型节点模块,可将流连接在一起并在其中一个关闭时将其全部销毁. 使用标准source.pipe(dest)源时,如果dest发出关 ...
- Parity game POJ - 1733 带权并查集
#include<iostream> #include<algorithm> #include<cstdio> using namespace std; <& ...
- laravel中redis数据库的简单使用
1.简介 性能极高 – Redis能读的速度是110000次/s,写的速度是81000次/s . 丰富的数据类型 – Redis支持二进制案例的 Strings, Lists, Hashes, Set ...
- 安装oracle client及配置
一.下载oracle client 下载地址:https://www.oracle.com/technetwork/database/enterprise-edition/downloads/1120 ...
- LeetCode longest substring without repeating characters 题解 Hash表
题目 Given a string, find the length of the longest substring without repeating characters. Example 1: ...
- python中的strip()方法
python中字符串str的strip()方法 str.strip()就是把字符串(str)的头和尾的空格,以及位于头尾的\n \t之类给删掉. 例1: str=" python " ...
- [Python]jieba切词 添加字典 去除停用词、单字 python 2020.2.10
源码如下: import jieba import io import re #jieba.load_userdict("E:/xinxi2.txt") patton=re.com ...
- java中类的构造方法出错点
大家请看下面的这个代码 package ppt_test; public class test1 { public static void main(String args[]) { Foo obj1 ...
- SpringData JPA快速入门和基本的CRUD操作以及Specifications条件查询
SpringData JPA概述: SpringData JPA 是 Spring 基于 ORM 框架.JPA 规范的基础上封装的一套JPA应用框架,可使开发者用极简的代码即可实现对数据库的访问和操作 ...