|
from flask import Flask, render_template, request, redirect, url_for, session |
|
import random |
|
|
|
app = Flask(__name__) |
|
app.secret_key = 'your_secret_key_here' |
|
|
|
questions ={ |
|
"MgCl2": 95.0, |
|
"MgO": 40.0, |
|
"MgF2": 62.0, |
|
"MgS": 56.0, |
|
"Mg(OH)2": 58.0, |
|
"MgI2": 278.0, |
|
"CaCl2": 111.0, |
|
"CaO": 56.0, |
|
"CaF2": 78.0, |
|
"CaS": 72.0, |
|
"Ca(OH)2": 74.0, |
|
"CaI2": 294.0, |
|
"ZnCl2": 136.0, |
|
"ZnO": 81.0, |
|
"ZnF2": 103.0, |
|
"ZnS": 97.0, |
|
"Zn(OH)2": 99.0, |
|
"ZnI2": 319.0, |
|
"NaCl": 58.5, |
|
"Na2O": 62.0, |
|
"NaF": 42.0, |
|
"Na2S": 78.0, |
|
"NaOH": 40.0, |
|
"NaI": 150.0, |
|
"KCl": 74.5, |
|
"K2O": 94.0, |
|
"KF": 58.0, |
|
"K2S": 110.0, |
|
"KOH": 56.0, |
|
"KI": 166.0, |
|
"HCl": 36.5, |
|
"H2O": 18.0, |
|
"HF": 20.0, |
|
"H2S": 34.0, |
|
"HOH": 18.0, |
|
"HI": 128.0, |
|
"CuCl": 99.0, |
|
"Cu2O": 143.0, |
|
"CuF": 82.5, |
|
"Cu2S": 159.0, |
|
"CuOH": 80.5, |
|
"CuI": 190.5, |
|
"CuCl2": 134.5, |
|
"CuO": 79.5, |
|
"CuF2": 101.5, |
|
"CuS": 95.5, |
|
"Cu(OH)2": 97.5, |
|
"CuI2": 317.5, |
|
"AgCl": 143.5, |
|
"Ag2O": 232.0, |
|
"AgF": 127.0, |
|
"Ag2S": 248.0, |
|
"AgOH": 125.0, |
|
"AgI": 235.0, |
|
"BaCl2": 208.0, |
|
"BaO": 153.0, |
|
"BaF2": 175.0, |
|
"BaS": 169.0, |
|
"Ba(OH)2": 171.0, |
|
"BaI2": 391.0, |
|
"FeCl2": 127.0, |
|
"FeO": 72.0, |
|
"FeF2": 94.0, |
|
"FeS": 88.0, |
|
"Fe(OH)2": 90.0, |
|
"FeI2": 310.0, |
|
"MnCl2": 126.0, |
|
"MnO": 71.0, |
|
"MnF2": 93.0, |
|
"MnS": 87.0, |
|
"Mn(OH)2": 89.0, |
|
"MnI2": 309.0, |
|
"PbCl2": 278.0, |
|
"PbO": 223.0, |
|
"PbF2": 245.0, |
|
"PbS": 239.0, |
|
"Pb(OH)2": 241.0, |
|
"PbI2": 461.0, |
|
"AlCl3": 133.5, |
|
"Al2O3": 102.0, |
|
"AlF3": 84.0, |
|
"Al2S3": 150.0, |
|
"Al(OH)3": 78.0, |
|
"AlI3": 408.0, |
|
"FeCl3": 162.5, |
|
"Fe2O3": 160.0, |
|
"FeF3": 113.0, |
|
"Fe2S3": 208.0, |
|
"Fe(OH)3": 107.0, |
|
"FeI3": 437.0, |
|
"NH4Cl": 53.5, |
|
"(NH4)2O": 52.0, |
|
"NH4F": 37.0, |
|
"(NH4)2S": 68.0, |
|
"NH4OH": 35.0, |
|
"NH4I": 145.0, |
|
"MgSO4": 120.0, |
|
"MgCO3": 84.0, |
|
"MgC2O4": 112.0, |
|
"MgCrO4": 140.0, |
|
"MgCr2O7": 240.0, |
|
"MgS2O3": 136.0, |
|
"Mg3(PO4)2": 262.0, |
|
"CaSO4": 136.0, |
|
"CaCO3": 100.0, |
|
"CaC2O4": 128.0, |
|
"CaCrO4": 156.0, |
|
"CaCr2O7": 256.0, |
|
"CaS2O3": 152.0, |
|
"Ca3(PO4)2": 310.0, |
|
"ZnSO4": 161.0, |
|
"ZnCO3": 125.0, |
|
"ZnC2O4": 153.0, |
|
"ZnCrO4": 181.0, |
|
"ZnCr2O": 185.0, |
|
"ZnS2O3": 177.0, |
|
"Zn3(PO4)2": 385.0, |
|
"Na2SO4": 142.0, |
|
"Na2CO3": 106.0, |
|
"Na2C2O4": 134.0, |
|
"Na2CrO4": 162.0, |
|
"Na2Cr2O7": 262.0, |
|
"Na2S2O3": 158.0, |
|
"Na3PO4": 164.0, |
|
"K2SO4": 174.0, |
|
"K2CO3": 138.0, |
|
"K2C2O4": 166.0, |
|
"K2CrO4": 194.0, |
|
"K2Cr2O7": 294.0, |
|
"K2S2O3": 190.0, |
|
"K3PO4": 212.0, |
|
"H2SO4": 98.0, |
|
"H2CO3": 62.0, |
|
"H2C2O4": 90.0, |
|
"H2CrO4": 118.0, |
|
"H2Cr2O7": 218.0, |
|
"H2S2O3": 114.0, |
|
"H3PO4": 98.0, |
|
"Cu2SO4": 223.0, |
|
"Cu2CO3": 187.0, |
|
"Cu2C2O4": 215.0, |
|
"Cu2CrO4": 243.0, |
|
"Cu2Cr2O7": 343.0, |
|
"Cu2S2O3": 239.0, |
|
"Cu3PO4": 285.5, |
|
"CuSO4": 159.5, |
|
"CuCO3": 123.5, |
|
"CuC2O4": 151.5, |
|
"CuCrO4": 179.5, |
|
"CuCr2O7": 279.5, |
|
"CuS2O3": 175.5, |
|
"Cu3(PO4)2": 380.5, |
|
"Ag2SO4": 312.0, |
|
"Ag2CO3": 276.0, |
|
"Ag2C2O4": 304.0, |
|
"Ag2CrO4": 332.0, |
|
"Ag2Cr2O7": 432.0, |
|
"Ag2S2O3": 328.0, |
|
"Ag3PO4": 419.0, |
|
"BaSO4": 233.0, |
|
"BaCO3": 197.0, |
|
"BaC2O4": 225.0, |
|
"BaCrO4": 253.0, |
|
"BaCr2O7": 353.0, |
|
"BaS2O3": 249.0, |
|
"Ba3(PO4)2": 601.0, |
|
"FeSO4": 152.0, |
|
"FeCO3": 116.0, |
|
"FeC2O4": 144.0, |
|
"FeCrO4": 172.0, |
|
"FeCr2O7": 272.0, |
|
"FeS2O3": 168.0, |
|
"Fe3(PO4)2": 358.0, |
|
"MnSO4": 151.0, |
|
"MnCO3": 115.0, |
|
"MnC2O4": 143.0, |
|
"MnCrO4": 171.0, |
|
"MnCr2O)": 175.0, |
|
"MnS2O3": 167.0, |
|
"Mn3(PO4)2": 355.0, |
|
"PbSO4": 303.0, |
|
"PbCO3": 267.0, |
|
"PbC2O4": 295.0, |
|
"PbCrO4": 323.0, |
|
"PbCr2O7": 423.0, |
|
"PbS2O3": 319.0, |
|
"Pb3(PO4)2": 811.0, |
|
"Al2(SO4)3": 342.0, |
|
"Al2(CO3)3": 234.0, |
|
"Al2(C2O4)3": 318.0, |
|
"Al2(CrO4)3": 402.0, |
|
"Al2(Cr2O7)3": 702.0, |
|
"Al2(S2O3)3": 390.0, |
|
"AlPO4": 122.0, |
|
"Fe2(SO4)3": 400.0, |
|
"Fe2(CO3)3": 292.0, |
|
"Fe2(C2O4)3": 376.0, |
|
"Fe2(CrO4)3": 460.0, |
|
"Fe2(Cr2O7)3": 760.0, |
|
"Fe2(S2O3)3": 448.0, |
|
"FePO4": 151.0, |
|
"Mg(NO3)2": 148.0, |
|
"Mg(CH3COO)2": 142.0, |
|
"Mg(MnO4)2": 262.0, |
|
"Ca(NO3)2": 164.0, |
|
"Ca(CH3COO)2": 158.0, |
|
"Ca(MnO4)2": 278.0, |
|
"Zn(NO3)2": 189.0, |
|
"Zn(CH3COO)2": 183.0, |
|
"Zn(MnO4)2": 303.0, |
|
"NaNO3": 85.0, |
|
"Na(CH3COO)": 82.0, |
|
"Na(MnO4)": 142.0, |
|
"KNO3": 101.0, |
|
"K(CH3COO)": 98.0, |
|
"K(MnO4)": 158.0, |
|
"HNO3": 63.0, |
|
"HCH3COO": 60.0, |
|
"HMnO4": 120.0, |
|
"CuNO3": 125.5, |
|
"CuCH3COO": 122.5, |
|
"CuMnO4": 182.5, |
|
"Cu(NO3)2": 187.5, |
|
"Cu(CH3COO)2": 181.5, |
|
"Cu(MnO4)2": 301.5, |
|
"AgNO3": 170.0, |
|
"AgCH3COO": 167.0, |
|
"AgMnO4": 227.0, |
|
"Ba(NO3)2": 261.0, |
|
"Ba(CH3COO)2": 255.0, |
|
"Ba(MnO4)2": 375.0, |
|
"Fe(NO3)2": 180.0, |
|
"Fe(CH3COO)2": 174.0, |
|
"Fe(MnO4)2": 294.0, |
|
"Mn(NO3)2": 179.0, |
|
"Mn(CH3COO)2": 173.0, |
|
"MnNO3": 117.0, |
|
"MnCH3COO": 114.0, |
|
"Mn(MnO4)2": 293.0, |
|
"Pb(NO3)2": 331.0, |
|
"Pb(CH3COO)2": 325.0, |
|
"Pb(MnO4)2": 445.0, |
|
"Al(NO3)3": 213.0, |
|
"Al(CH3COO)3": 204.0, |
|
"Al(MnO4)3": 384.0, |
|
"Fe(NO3)3": 242.0, |
|
"Fe(CH3COO)3": 233.0, |
|
"Fe(MnO4)3": 413.0, |
|
"Mn(NO3)3": 241.0, |
|
"Mn(CH3COO)3": 232.0, |
|
"Mn(MnO4)3": 412.0, |
|
"Pb(NO3)3": 393.0, |
|
"Pb(CH3COO)3": 384.0, |
|
"Pb(MnO4)3": 564.0, |
|
"Al(NO3)2": 151.0, |
|
"Al(CH3COO)2": 145.0, |
|
"Al(MnO4)2": 265.0, |
|
} |
|
def get_random_question(): |
|
question = random.choice(list(questions.keys())) |
|
return question, questions[question] |
|
|
|
@app.route('/', methods=['GET', 'POST']) |
|
def quiz(): |
|
if 'current_question' not in session: |
|
session['current_question'], session['current_answer'] = get_random_question() |
|
|
|
result = None |
|
|
|
if request.method == 'POST': |
|
user_input = request.form['user_input'] |
|
if user_input == session['current_answer']: |
|
result = '正解です!' |
|
else: |
|
result = '不正解です。正解は{}です。'.format(session['current_answer']) |
|
|
|
return render_template('quiz.html', question=session['current_question'], result=result) |
|
|
|
@app.route('/next', methods=['POST']) |
|
def next_question(): |
|
session.pop('current_question') |
|
session.pop('current_answer') |
|
return redirect(url_for('quiz')) |
|
|
|
if __name__ == '__main__': |
|
app.run(debug=True, port=7860, host="0.0.0.0") |