File size: 1,867 Bytes
6aa9259
8b41da9
 
 
6aa9259
9deadaf
 
508cbf9
 
 
 
 
 
 
0e6f883
8651983
9deadaf
 
6aa9259
9deadaf
 
e2daa05
6aa9259
 
8b41da9
9deadaf
8b41da9
9deadaf
a3f4faa
6aa9259
9deadaf
 
6aa9259
9deadaf
6aa9259
8b41da9
9deadaf
e2daa05
6aa9259
 
9deadaf
6066cfe
9deadaf
6aa9259
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from flask import Flask, render_template, request, redirect, url_for, session
import random

app = Flask(__name__)
app.secret_key = 'your_secret_key_here'  # セッションの安全な署名に必要なキー

capitals = {
    'H': 1, 'He': 2,
    'Li': 3, 'Be': 4, 'B': 5, 'C': 6, 'N': 7, 'O': 8, 'F': 9, 'Ne': 10,
    'Na': 11, 'Mg': 12, 'Al': 13, 'Si': 14, 'P': 15, 'S': 16, 'Cl': 17, 'Ar': 18,
    'K': 19, 'Ca': 20, 'Sc': 21, 'Ti': 22, 'V': 23, 'Cr': 24, 'Mn': 25, 'Fe': 26, 'Co': 27, 'Ni': 28, 'Cu': 29, 'Zn': 30,
    'Ga': 31, 'Ge': 32, 'As': 33, 'Se': 34, 'Br': 35, 
    'Rb': 37, 'Sr': 38, 'Y': 39, 'Zr': 40, 'Nb': 41, 'Mo': 42, 'Tc': 43, 'Ru': 44, 'Rh': 45, 'Pd': 46, 'Ag': 47, 'Cd': 48,
    'In': 49, 'Sn': 50, 'Sb': 51, 'I': 53, 'Xe': 54,
}

def get_random_country():
    country = random.choice(list(capitals.keys()))
    return country, capitals[country]

@app.route('/', methods=['GET', 'POST'])
def quiz():
    if 'current_化合物' not in session:  # セッションに現在の化合物がない場合は新しいものを取得
        session['current_化合物'], session['current_化合物名'] = get_random_country()
    
    result = None

    if request.method == 'POST':
        user_input = int(request.form['user_input'])
        if user_input == session['current_化合物名']:
            result = '正解です!'
        else:
            result = '不正解です。正解は{}です。'.format(session['current_化合物名'])
    
    return render_template('quiz.html', element=session['current_化合物'], result=result)

@app.route('/next', methods=['POST'])
def next_question():
    session.pop('current_化合物')  # 現在の化合物をセッションから削除
    session.pop('current_化合物名')
    return redirect(url_for('quiz'))

if __name__ == '__main__':
    app.run(debug=True, port=7860, host="0.0.0.0")