import turtle
qlist = ['整数在python中是用什么表示的?',
'python中输出是什么语句',
'python里turtle是干嘛的',
'条件判断的关键字是什么?',
'RGB能描述多少种颜色?']
alist = ['int','print','画画的','elif','255']
tablist = [['int', 'abs','str'],
['input','print','write'],
['打字的', '画画的','听音乐的'],
['elif', 'eilf', 'lief'],
['225','252','255']]
poslist = [[-100, -200], [0, -200], [100, -200]]
q_index = 1 #题目索引
p = turtle.Pen()
p.hideturtle()
def drawText(pen, color, text):
pen.pencolor(color)
pen.write(text, font=('Arial', 20))
def getQuestion(index):
p.clear()
p.penup()
if index == len(qlist):
drawText(p, 'green', '已通关')
return
p.goto(-180, 0)
drawText(p, 'green', qlist[index])
for i in range(len(tablist[index])):
p.penup()
p.goto(poslist[i][0] - 50, poslist[i][1])
drawText(p, 'green', tablist[index][i])
def checkPosition(x, y):
global q_index
if q_index == len(qlist):
drawText(p, 'green', '已通关')
return
for i in range(len(tablist[q_index])):
if poslist[i][0] - 80 < x < poslist[i][0] and poslist[i][1] < y < poslist[i][1] + 80:
if tablist[q_index][i] == alist[q_index]:
q_index += 1
getQuestion(q_index)
getQuestion(q_index)
turtle.onscreenclick(checkPosition)
turtle.done()
学习问题回顾
最新推荐文章于 2022-10-18 22:47:23 发布