#coding=utf-8
import random
model = ['工厂方法','抽象工厂','单例','原型','建造者','适配器','桥接','组合','装饰','外观','享元','代理','观察者','访问者','中介者','解释器','迭代器','状态','命令','策略','备忘录','责任链','模板方法']
num = 0
trueNum = 0
type = ''
while(True):
i = random.choice(range(23))
if(i<5):
type = '创建'
elif(i>11):
type = '行为'
else:
type = '结构'
print(num+1,":请判断<",model[i],">是什么类型的设计模式")
print("0:退出")
print("1:创建")
print("2:结构")
print("3:行为")
typeNum = input()
if(typeNum=='0'):
print("此题不计入成绩")
break
if(typeNum=='1'):
if(i<5):
print("猜对了")
trueNum += 1
else:
print("猜错了,是",type)
if(typeNum=='2'):
if(i>4 and i<12):
print("猜对了")
trueNum += 1
else:
print("猜错了,是",type)
if(typeNum=='3'):
if(i>11):
print("猜对了")
trueNum += 1
else:
print("猜错了,是",type)
if(typeNum=='0' or typeNum=='1' or typeNum=='2' or typeNum=='3'):
num += 1
else:
print("输入的格式有错,此题不计入成绩")
print("一共答了",num,"题,答对了",trueNum,"题")
用于判断设计模式的小游戏
猜你喜欢
转载自blog.csdn.net/weixin_41671390/article/details/85250343
今日推荐
周排行