OzoneAsai commited on
Commit
17db4dd
1 Parent(s): 6066cfe

Update outerElectronFl.py

Browse files
Files changed (1) hide show
  1. outerElectronFl.py +35 -28
outerElectronFl.py CHANGED
@@ -4,30 +4,37 @@ import random
4
  app = Flask(__name__)
5
  app.secret_key = "your_secret_key_here"
6
 
7
- # 元素と最外殻電子の数の辞書
8
- element_outer_electrons: dict[str, int] = {
9
- "水素": 1,
10
- "ヘリウム": 2,
11
- "リチウム": 1,
12
- "ベリリウム": 2,
13
- "ホウ素": 3,
14
- "炭素": 4,
15
- "窒素": 5,
16
- "酸素": 6,
17
- "フッ素": 7,
18
- "アルゴン": 8,
19
- "クリプトン": 8,
20
- "キセノン": 8,
21
- "ナトリウム": 1,
22
- "マグネシウム": 2,
23
- "アルミニウム": 3,
24
- "ケイ素": 4,
25
- "リン": 5,
26
- "硫黄": 6,
27
- "塩素": 7,
28
- "カリウム": 1,
29
- "カルシウム": 2,
30
- # 他の元素も追加可能
 
 
 
 
 
 
 
31
  }
32
 
33
  # 首都のデータを辞書に格納する
@@ -146,11 +153,11 @@ def next_question_element():
146
  def quiz_element2num():
147
  # セッションに元素がない場合はランダムに選択
148
  if "element" not in session:
149
- session["element"] = random.choice(list(element_atomic_numbers.keys()))
150
 
151
  if request.method == "POST":
152
  user_input = int(request.form["user_input"])
153
- correct_answer = element_atomic_numbers[session["element"]]
154
  if user_input == correct_answer:
155
  result = "正解です!"
156
  else:
@@ -162,8 +169,8 @@ def quiz_element2num():
162
  @app.route("/next_element2num", methods=["POST"])
163
  def next_question_element2num():
164
  # 次の問題をセッションに設定し、リダイレクト
165
- session["element"] = random.choice(list(element_atomic_numbers.keys()))
166
  return redirect(url_for("quiz_element2num"))
167
 
168
  if __name__ == '__main__':
169
- app.run(debug=True, port=7860)
 
4
  app = Flask(__name__)
5
  app.secret_key = "your_secret_key_here"
6
 
7
+ element_atomic_numbers = {
8
+ 1: ['H', '水素 (Hydrogen)'],
9
+ 2: ['He', 'ヘリウム (Helium)'],
10
+ 3: ['Li', 'リチウム (Lithium)'],
11
+ 4: ['Be', 'ベリリウム (Beryllium)'],
12
+ 5: ['B', 'ホウ素 (Boron)'],
13
+ 6: ['C', '炭素 (Carbon)'],
14
+ 7: ['N', '窒素 (Nitrogen)'],
15
+ 8: ['O', '酸素 (Oxygen)'],
16
+ 9: ['F', 'フッ素 (Fluorine)'],
17
+ 10: ['Na', 'ナトリウム (Sodium)'],
18
+ 11: ['Al', 'アルミニウム (Aluminium)'],
19
+ 12: ['Si', 'ケイ素 (Silicon)'],
20
+ 13: ['P', 'リン (Phosphorus)'],
21
+ 14: ['S', '硫黄 (Sulfur)'],
22
+ 15: ['Cl', '塩素 (Chlorine)'],
23
+ 16: ['K', 'カリウム (Potassium)'],
24
+ 17: ['Ti', 'チタン (Titanium)'],
25
+ 18: ['Cr', 'クロム (Chromium)'],
26
+ 19: ['Mn', 'マンガン (Manganese)'],
27
+ 20: ['Fe', '鉄 (Iron)'],
28
+ 21: ['Cu', '銅 (Copper)'],
29
+ 22: ['Zn', '亜鉛 (Zinc)'],
30
+ 23: ['As', 'ヒ素 (Arsenic)'],
31
+ 24: ['Se', 'セレン (Selenium)'],
32
+ 25: ['Br', '臭素 (Bromine)'],
33
+ 26: ['Nb', 'ニオブ (Niobium)'],
34
+ 27: ['Mo', 'モリブデン (Molybdenum)'],
35
+ 28: ['Ag', '銀 (Silver)'],
36
+ 29: ['Sn', 'スズ (Tin)'],
37
+ 30: ['Sb', 'アンチモン (Antimony)']
38
  }
39
 
40
  # 首都のデータを辞書に格納する
 
153
  def quiz_element2num():
154
  # セッションに元素がない場合はランダムに選択
155
  if "element" not in session:
156
+ session["element"] = random.choice(list(element_atomic_numbers.values()))[1]
157
 
158
  if request.method == "POST":
159
  user_input = int(request.form["user_input"])
160
+ correct_answer = [key for key, value in element_atomic_numbers.items() if value[1] == session["element"]][0]
161
  if user_input == correct_answer:
162
  result = "正解です!"
163
  else:
 
169
  @app.route("/next_element2num", methods=["POST"])
170
  def next_question_element2num():
171
  # 次の問題をセッションに設定し、リダイレクト
172
+ session["element"] = random.choice(list(element_atomic_numbers.values()))[1]
173
  return redirect(url_for("quiz_element2num"))
174
 
175
  if __name__ == '__main__':
176
+ app.run(debug=True, port=7860)