跳到正文

剪贴板

剪贴板 lbde0l9k

原文
剪贴板信息

剪贴板信息

收录
更新
Python
from tkinter import simpledialog, messagebox
from random import randint as r
from time import *
from std import random

score = 0
stage = None


def check_level(stage):
    if stage == 1:
        questions(1, 6, '+', 1)
    elif stage == 2:
        questions(1, 6, '+', 2)
    elif stage == 3:
        questions(1, 6, '-', 3)
    elif stage == 4:
        questions(1, 6, '-', 4)
    elif stage == 5:
        questions(1, 10, '+', 5)
    elif stage == 6:
        questions(1, 11, '+', 6)
    elif stage == 7:
        questions(1, 11, '+', 7)
    elif stage == 8:
        questions(1, 10, '-', 8)
    elif stage == 9:
        questions(1, 10, '-', 9)
    elif stage == 10:
        questions(1, 11, '-', 10)
    elif stage == 11:
        questions(1, 11, '-', 11)
    elif stage == 12:
        questions(1, 6, '*', 12)
    elif stage == 13:
        questions(1, 11, '*', 13)
    elif stage == 14:
        questions(1, 11, '*', 14)
    elif stage == 15:
        questions(1, 11, '*', 15)
    elif stage == 16:
        questions(1, 11, '/', 16)
    elif stage == 17:
        questions(1, 11, '/', 17)
    elif stage == 18:
        questions(1, 11, '/', 18)
    elif stage == 19:
        questions(1, 16, '/', 19)
    elif stage == 20:
        questions(1, 16, '/', 20)
    elif stage == 21:
        questions(10, 16, '*', 21)
    elif stage == 22:
        questions(10, 16, '*', 22)
    elif stage == 23:
        questions(10, 51, '+', 23)
    elif stage == 24:
        questions(10, 51, '-', 24)
    elif stage == 25:
        questions(1, 101, '+', 25)
    elif stage == 26:
        questions(1, 101, '-', 26)
    elif stage == 27:
        questions(1, 101, '-', 27)
    elif stage == 28:
        questions(15, 21, '*', 28)
    elif stage == 29:
        questions(15, 21, '*', 29)
    elif stage == 30:
        questions(10, 21, '*', 30)
    elif stage == 31:
        questions(10, 21, '*', 31)
    elif stage == 32:
        questions(100, 1001, '+', 32)
    elif stage == 33:
        questions(100, 1001, '-', 33)
    elif stage == 34:
        questions(10, 1001, '+', 34)
    elif stage == 35:
        questions(10, 1001, '-', 35)
    elif stage == 36:
        questions(1, 1001, '+', 36)
    elif stage == 37:
        questions(1, 1001, '+', 37)
    elif stage == 38:
        questions(1, 1001, '-', 38)
    elif stage == 39:
        questions(1, 1001, '-', 39)
    elif stage == 40:
        questions(1, 1001, '-', 40)
    elif stage == 41:
        messagebox.showinfo('Stage', ('Stage ' + str(stage) + ', (if it\'s a division, please input an integer.)'))
        for i in range(20):
            a = random(1)
            show_question(str(a) + '²=?', a ** 2, 5)
        stage += 1
        check_level(stage)
    elif stage == 42:
        messagebox.showinfo('Stage', ('Stage ' + str(stage) + ', (if it\'s a division, please input an integer.)'))
        for i in range(20):
            a = random(1) + 10
            show_question(str(a) + '²=?', a ** 2, 5)
        stage += 1
        check_level(stage)
    elif stage == 43:
        questions(10, 30, '*', 43)
    elif stage == 44:
        questions(1, 30, '*', 44)
    elif stage == 45:
        questions(1, 31, '*', 45)
    elif stage == 46:
        questions(1, 31, '*', 46)
    elif stage == 47:
        questions(4, 400, '/', 47)
    elif stage == 48:
        questions(4, 400, '/', 48)
    elif stage == 49:
        questions(1, 400, '/', 49)
    elif stage == 50:
        questions(1, 100000000, '+', 50)
    elif stage == 51:
        questions(1, 100000000, '+', 51)
    elif stage == 52:
        questions(1, 999999999, '+', 52)
    elif stage == 53:
        questions(1, 999999999, '+', 53)
    elif stage == 54:
        questions(1, 100000000, '-', 54)
    elif stage == 55:
        questions(1, 100000000, '-', 55)
    elif stage == 56:
        questions(1, 999999999, '-', 56)
    elif stage == 57:
        questions(1, 999999999, '-', 57)
    elif stage == 58:
        questions(1, 999999999, '-', 58)
    elif stage == 59:
        questions(1, 50, '*', 59)
    elif stage == 60:
        questions(1, 50, '*', 60)
    elif stage == 61:
        questions(1, 50, '*', 61)
    elif stage == 62:
        questions(1, 50, '*', 62)
    elif stage == 63:
        questions(1, 10000, '/', 63)
    elif stage == 64:
        questions(1, 10000, '/', 64)
    elif stage == 65:
        questions(1, 100000, '/', 65)
    elif stage == 66:
        questions(1, 1000000, '/', 66)
    elif stage == 67:
        questions(1, 100, '*', 67)
    elif stage == 68:
        questions(1, 1000, '*', 68)
    elif stage == 69:
        questions(1, 100000, '*', 69)
    elif stage == 70:
        questions(1, 10000000, '*', False)
    else:
        messagebox.showinfo('End', 'The End')


def show_question(question, answer, points=4):
    global score
    next = True
    times = 1
    points += 1
    while next == True and times <= 3:
        try:
            ANSWER = int(simpledialog.askstring('Question', question))
        except:
            messagebox.showerror('Value Error', 'Please input an integer.')
            ANSWER = 0
            break
        if int(answer) == int(ANSWER):
            messagebox.showinfo('Correct', 'Correct answer')
            next = False
            score += (points - times)
        else:
            messagebox.showwarning('Wrong', 'Wrong answer,you have %d chances' % (3 - times))
            times += 1
    sleep(0.5)


def questions(enter1, enter2, sign='*', stage=stage):
    global score
    if bool(stage):
        messagebox.showinfo('Stage', ('Stage ' + str(stage) + ', (if it\'s a division, please input an integer.)'))
    else:
        messagebox.showinfo('Stage', 'FINAL STAGE')
    if sign == '+':
        while score <= 80:
            for i in range(20):
                a = r(enter1, enter2)
                b = r(enter1, enter2)
                show_question((str(a) + '+' + str(b) + '=?'), a + b, 5)
            sleep(1.5)
            messagebox.showinfo('Points', 'Your point is %s points.' % score)
    if sign == '-':
        while score <= 80:
            for i in range(20):
                a = r(enter1, enter2)
                b = r(enter1, enter2)
                big = max(a, b)
                small = min(a, b)
                show_question((str(big) + '-' + str(small) + '=?'), big - small, 5)
            sleep(1.5)
            messagebox.showinfo('Points', 'Your point is %s points.' % score)
    if sign == '*':
        while score <= 80:
            for i in range(20):
                a = r(enter1, enter2)
                b = r(enter1, enter2)
                show_question((str(a) + '×' + str(b) + '=?'), a * b, 5)
            sleep(1.5)
            messagebox.showinfo('Points', 'Your point is %s points.' % score)
    else:
        while score <= 80:
            for i in range(20):
                a = r(enter1, enter2)
                b = r(enter1, enter2)
                show_question((str(a) + '÷' + str(b) + '=?'), round(a / b), 5)
            sleep(1.5)
            messagebox.showinfo('Points', 'Your point is %s points.' % score)
    score = 0
    stage += 1
    check_level(stage)


def level():
    global stage

    hard = simpledialog.askstring('Hard', 'Would you like to choose which level: L1, L2 ,L3, L4, L5, L6, L7, FINAL?')
    hard = hard.upper()
    if hard == 'L1':
        stage = 1
    elif hard == 'L2':
        stage = 12
    elif hard == 'L3':
        stage = 21
    elif hard == 'L4':
        stage = 41
    elif hard == 'L5':
        stage = 50
    elif hard == 'L6':
        stage = 59
    elif hard == 'L7':
        stage = 63
    elif hard == 'FINAL':
        stage = 70
    else:
        messagebox.showwarning('Warning', 'It\'s not a level.')
        level()


level()
check_level(stage)