题目的格式如下,题目和题目之间用“==”隔开,每个题目的“题干”,“选项”,“答案”用“*”号隔开

An administrator wants to provide users restricted access. The users should only be able to perform the following
tasks:
- Create and consolidate virtual machine snapshots
- Add/Remove virtual disks
- Snapshot Management
Which default role in vCenter Server would meet the administrator's requirements for the users?
*
A. Virtual machine user
B. Virtual machine power user
C. Virtual Datacenter administrator
D. VMware Consolidated Backup user
*
B
==
Which two roles can be modified? (Choose two.)
*
A. Administrator
B. Network Administrator
C. Datastore Consumer
D. Read-Only
*
BC

 

 

#Auther Bob
#--*--coding:utf-8--*--
import time
import random
score = 0             #记录分数,答对一题加10分,打错不扣分
y = []                #定义一个list,主要放已经答过的题目,如果在该list中,则跳出这次循环开始下一次循环
temp_int = 0          #统计循环的次数,如果所有题目全部打完,则退出循环
exam_list = []        #定义一个list,该list主要是生成题目的序号
temp_list = []        #定义一个list,把所有的题目放在一个list中
l2 = []               #定义一个list,把所有的题目按照“===”分割,每个题目作为一个该list的一个元素
correct = 0           #定义答错的题目的数量
fail = 0              #定义答对的题目的数量

exam_dict = {}        #定义一个dict,格式化如下{序号:{题目:“题目内容”,选项:“选项内容”,答案:“答案内容”}}
for i in range(242):
    exam_list.append(i)

with open("exam","r",encoding="utf-8") as f:
    for line in f:
        temp_list.append(line)
temp_str = "".join(temp_list)
l2 = temp_str.split("==")
for a in exam_list:
    l1 = l2[a].split("*")
    temp_dict = {a:{"题目":l1[0],"选项":l1[1],"答案":l1[2]}}
    exam_dict.update(temp_dict)


while True:
    r = random.randrange(0,242)
    if temp_int == 242:
        test_num = "你一共测试了%d道题,答对%d,答错%d" %(temp_int,correct,fail)
        test_score = "你的分数是%d." %(score)
        print(test_score)
        print(test_num)
        exit()

    else:
        if r in y:
            continue
        else:
            g = "good"
            f = "failed"
            temp_int = temp_int + 1
            y.append(r)
            tmp_num = "这是第%d道题." % (temp_int)
            print(tmp_num)
            print(exam_dict[r]["题目"])
            print(exam_dict[r]["选项"])
            temp_option = input("you choice:")
            option = temp_option.upper()
            s = set()
            b = set()
            for i in option:
                s.add(i)
            for c in exam_dict[r]["答案"].strip():
                b.add(c)
            if s == b:
                gg = g.center(100,"=")
                print(gg)
                correct = correct + 1
                test_num = "你一共测试了%d道题,答对%d,答错%d" % (temp_int, correct, fail)
                print(test_num)
                score = score + 10

            else:
                ff = f.center(100,"=")
                print(ff)
                fail = fail + 1
                time.sleep(10)
                print(b)
                test_num = "你一共测试了%d道题,答对%d,答错%d" % (temp_int, correct, fail)
                print(test_num)
                time.sleep(15)

  

  

  

  

posted on 2017-05-27 07:27  bainianminguo  阅读(900)  评论(0编辑  收藏  举报