print(yate.para('1.请设置计算值范围'))
print(yate.select_set('numlist', NumList, SelectedVals=numlist_checked))
print(yate.para('2.请设置使用的运算符'))
for key in OperatorList:
    checkedVal = False
    if (OperatorList[key][0] in operator_checked):
        checkedVal = True
    print(
        yate.checked_box('operator',
                         OperatorList[key][0],
                         OperatorList[key][1],
                         key,
                         checked=checkedVal))
print(yate.para('3.请设置计算数个数'))
print(yate.select_set('level', NumLevel, SelectedVals=level_checked))
print(yate.input_hidden('NewSetting', 1))  #设置是否为新设置的标识(设置页面初始化为1)
# print(yate.input_hidden('StartCal', 1))    #设置开始计算训练标识
print(yate.para(''))
print(yate.subbutton('自由练习', 'FreeExerAction()', style='sub'))
print(' ' * 4)
print(yate.subbutton('进行测验', 'ExamAction()', style='sub'))
print('</form>')

# =====================设置页脚的链接(保持固定顺序)=====================
FooterString = OrderedDict()
FooterString['返回首页'] = '/index.html'
FooterString['错题回顾'] = 'WrongRecord.py'
FooterString['测验回顾'] = 'ExamRecords.py'
AwardString = yate.img_tag('/images/奖励.png') + '<span style="font-weight:bolder;color:#FF6666;"> × %d</span> ' % (AwardCount[0])\
              + ' + ' + yate.img_tag('/images/星.png') + '<span style="font-weight:bolder;color:#FF6666;"> × %d</span> ' % (AwardCount[1])\
              + '&nbsp;&nbsp;<span style="font-weight:bolder;color:#FF6666;">兑换奖励</span>'
                form_data['ExamCount'].value)  #保存测验题目数
        ExamRecJson['ExamRecords'][data_string][str(ExamNum)]['ExamTime'] = (
            ExamTimeInitSeconds, ExamTimeActSeconds)  #保存考试规定用时和实际用时
        ExamRecJson['AwardCount'] = AwardCount  #保存奖励数量
        record_string = json.dumps(ExamRecJson)
        ExamRecFile.write(record_string)

else:
    print(
        yate.header(
            '本次考试出问题啦,请点击&nbsp;' + yate.a_link('/index.html', '返回首页') +
            '&nbsp;重新生成试题', 1))

# =================== 下面是将算术题参数回传 ===================
print(yate.start_form('exam.py', 'name'))
print(yate.input_hidden('numlist', form_data['numlist'].value))
for Operator in [x.value for x in form_data['operator']]:
    print(yate.input_hidden('operator', Operator))
print(yate.input_hidden('level', form_data['level'].value))
print(yate.input_hidden('NewSetting', form_data['NewSetting'].value))
#下面是将错题传到表单里
WrongQuestionJson = {}
if (WrongExpList):
    for AwrongQuestion in WrongExpList:
        WrongQuestionJson[AwrongQuestion.ExpNum] = (
            AwrongQuestion.ArithmeticExpress, AwrongQuestion.FactResult, 0
        )  #{题号:(表达式,正确答案, 错误标记)} --错误标记:错题修订成功后,该标记变成1
    print(yate.input_hidden('WrongQuestions'))  #把错题数据做为一个JSON格式字符串传到表单
    print(
        '<script>var jsonString = JSON.stringify(%s); document.name.WrongQuestions.value=jsonString;</script>'
        % json.dumps(WrongQuestionJson))  #将json对象转换为JSON字符串
    print('<tr>%s%s%s%s%s</tr>' % (
        yate.td_tag('等级' + AwardLevel),
        yate.td_tag(AwardTable[AwardLevel]['AwardValue'],
                    id='level' + AwardLevel),
        yate.td_tag(
            img_string +
            '<span style="position:relative;top:-8px;left:2px"> × %d </span>' %
            AwardTable[AwardLevel]['AwardReq']),
        yate.td_tag(AwardTable[AwardLevel]['AwardReq'],
                    id='value' + AwardLevel,
                    display=False),
        yate.td_tag(
            yate.subbutton(
                '兑换',
                'Awardconfirm(\'%s\',\'%s\',\'%s\')' %
                ('level' + AwardLevel, 'value' + AwardLevel, 'AwardCountid'),
                status=status_string,
                style=style_string))))
print('</table>')
print('<div id="AwardCountid" style="display:none;">%d</div>' % RealAwardCount)

# ======= 以下构造一个表单,将本次兑换花费奖励值传给后台 ========
print(yate.start_form('AwardTable.py', name='formAward'))
print(yate.input_hidden('awardcost'))
print('</form>')

# ======= 以下为页脚部分 ========
FooterString = OrderedDict()
FooterString['返回首页'] = '/index.html'
FooterString['开始练习'] = 'expresssion_set.py'
print(yate.include_footer(FooterString))
Exemple #4
0
    #     except ZeroDivisionError:
    #         continue
    # action_URL = 'judge_result.py'
    header_string1 = '请输入计算结果再提交'

    # re_answer_tag = 1


# if(header_string1):
print(yate.header(header_string1,3))
print(yate.header(
    '第 %d 题  ----> 已答对<font color = "green"> %d </font>题,答错<font color="red"> %d </font>题(已纠正 <font color="blue"> %d </font>题)'
    % (ExpNum, (ExpNum - WrongNum - 1), WrongNum, CorrectNum), 4))
print(yate.start_form('judge_result.py'))
# =================在页面上记录上之前的设置参数=================
print(yate.input_hidden('numlist', form_data['numlist'].value))
for Operator in OperatorList:
    print(yate.input_hidden('operator', Operator))
print(yate.input_hidden('level', form_data['level'].value))
print(yate.input_hidden('ExpNum', ExpNum))
print(yate.input_hidden('WrongNum', WrongNum))
print(yate.input_hidden('WrongTag', WrongTag))
print(yate.input_hidden('CorrectNum', CorrectNum))
print(yate.input_hidden('NewSetting', 0))
print(yate.input_hidden('ArithmeticExpress', ArithmeticExpress))
print(yate.input_hidden('FactResult', str(FactResult)))
#==============================记录完毕================================

print(yate.header('%s' % (ArithmeticExpress + ' = &nbsp;&nbsp;' + yate.create_inputs('CalResult', style='input_control')), 2))

print(yate.para(''))
            'document.form.totaltime.value = totalseconds}var timer=setTimeout("countdown()",1000);'

# =================生成一个HTML页面=================
print(yate.start_response())
print(yate.include_header_js('欢迎来到韦浩宇的算术运算训练营!', JS_string))
# print(yate.start_form('arithmetic_training_games.py'))
print(yate.header('欢迎来到韦浩宇的算术运算训练营!', 1))
print(yate.header(header_string1, 2))
print(
    yate.header(
        '第 %d 题, 计时:<span id="timeshow"></span> ----> 已答对<font color = "green"> %d </font>题,答错<font color="red"> %d </font>题(已纠正 <font color="blue"> %d </font>题)'
        % (ExpNum, RightAnsNum, WrongNum, CorrectNum), 4))
print(yate.start_form('generate_expression.py', name='form'))

# =================在页面上记录上之前的设置参数=================
print(yate.input_hidden('numlist', form_data['numlist'].value))
for Operator in OperatorList:
    print(yate.input_hidden('operator', Operator))
print(yate.input_hidden('level', form_data['level'].value))
print(yate.input_hidden('ArithmeticExpress', ArithmeticExpress))
print(yate.input_hidden('FactResult', FactResult))
print(yate.input_hidden('ExpNum', ExpNum))
print(yate.input_hidden('WrongNum', WrongNum))
print(yate.input_hidden('WrongTag', WrongTag))
print(yate.input_hidden('CorrectNum', CorrectNum))
print(yate.input_hidden('NewSetting', NewSettingTag))  #设置是否为新设置的标识(其他页面为0)
print(yate.input_hidden('RightAnsNum', RightAnsNum))
print(yate.input_hidden('RegenerationTag', 0))
print(yate.input_hidden('totaltime'))  #把练习用时传过去(由JS提供值)

#===========================================================
JS_string = ''
#==================== 输出错题页面 ====================
print(yate.start_response())
print(yate.include_header_js('欢迎来到韦浩宇的算术运算训练营!', JS_string))
print(
    yate.header(
        '<span style="color:#ff6666">下面是你本次测验的全部错题,赶紧进行更正吧,会有奖励哦!</span>', 2))
print(yate.start_form('WrongCorrect.py', 'formname'))

# 循环输出所有错题,已经修订正确的错题则不再显示输入框
for Astring in ShowWrongQuestions:
    print(yate.header(Astring, 2))

if (WQLeftTag == 1):
    # =====================更正后仍有错题,需要设置回传表单的内容=====================
    print(yate.input_hidden('WrongQuestions'))  #把所有错题传回表单
    print(
        '<script>var jsonString = JSON.stringify(%s); document.formname.WrongQuestions.value=jsonString;</script>'
        % json.dumps(WrongQuestionList))  # 将json对象转换为JSON字符串
    print(yate.end_form('确定', 'sub'))
elif (WQLeftTag == 2):
    print('</form>')
else:
    # =====================更正后没有错题,无需再次提交表单=====================
    print('</form>')
    print(
        yate.header(
            '恭喜您,所有错题都已经更正完毕,奖励 %s × 1, (10个 %s 可兑换1个 %s )' %
            (yate.img_tag(AwardImageURL2), yate.img_tag(AwardImageURL2),
             yate.img_tag(AwardImageURL1)), 2))
    # ====================== 把奖励值写回文件 ======================
#! /usr/local/bin/python3
# -*- coding: utf-8 -*-

import yate, cgi, json, cgitb
from collections import OrderedDict

cgitb.enable()
form_data = cgi.FieldStorage()
score = 0  #初始化考试成绩
RightNum = 0
# =================== 下面是实例化考试成绩判断对象 ===================
print(yate.start_response())
print(yate.include_header('欢迎来到韦浩宇的算术运算训练营!'))

print(yate.start_form('page_test.py'))
print(yate.input_hidden('testlist', 'apple'))
print(yate.input_hidden('testlist', 'banana'))
print(yate.end_form('确定', 'sub'))

try:
    for Afruit in form_data['testlist']:
        print(yate.header('这是一个%s' % Afruit.value, 2))

except KeyError:
    print('<script>alert(\'%s\')</script>' % ('发生错误,没有获取到任何一个水果!---->'))

# =====================设置页脚的链接(保持固定顺序)=====================
FooterString = OrderedDict()
FooterString['返回首页'] = '/index.html'
FooterString['考题回顾'] = '#'
print(yate.include_footer(FooterString))
Exemple #8
0
print(yate.start_response())
print(yate.include_header_js('欢迎来到韦浩宇的算术运算训练营!', JS_string))
# print(yate.start_form('arithmetic_training_games.py'))
print('<div id="topfixed">')
print(yate.header('欢迎来到韦浩宇的算术运算训练营!', 1))
print(
    yate.header(
        '开始算术测验%s<span class="timeshow">开始计时:</span><span  id="timeshow" class="timeshow"></span>'
        % ('&nbsp;' * 8), 2))
print('</div>')
print('<div style="margin-top:125px">')
print(yate.start_form('exam_result.py', name='form'))

for key in sorted(ExamList.keys()):
    ExamData = 'ExamData' + str(key)  #在页面上记录本次考题和答案
    print(yate.input_hidden(ExamData, str(key)))
    print(yate.input_hidden(ExamData, ExamList[key][0]))
    print(yate.input_hidden(ExamData, str(ExamList[key][1])))
    print(
        yate.header(
            '<span class="specfont">%d.</span>&nbsp;&nbsp;&nbsp;&nbsp;%s' %
            (key, ExamList[key][0] + ' = &nbsp;&nbsp;' +
             yate.create_inputs(ExamData, style='input_control')), 2))
# ================= 在页面上记录上之前的设置参数 =================
print(yate.input_hidden('numlist', form_data['numlist'].value))
for Operator in OperatorList:
    print(yate.input_hidden('operator', Operator))
print(yate.input_hidden('level', form_data['level'].value))
print(yate.input_hidden('ExamCount', ExamCount))  #把考试题目数量传过去
print(yate.input_hidden('NewSetting', NewSettingTag))
print(yate.input_hidden('totaltime'))  #把考试用时传过去(由JS提供值)