OzoneAsai commited on
Commit
d2540d6
1 Parent(s): 8afab12

Upload 4 files

Browse files
capitals.json ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "イギリス": "ロンドン",
45
+ "バチカン": "バチカン",
46
+ "アルメニア": "エレバン",
47
+ "アゼルバイジャン": "バクー",
48
+ "キプロス": "ニコシア",
49
+ "ジョージア": "トビリシ",
50
+ "イスラエル": "エルサレム",
51
+ "カザフスタン": "アスタナ",
52
+ "トルコ": "アンカラ",
53
+ "エチオピア": "アディスアベバ"
54
+ }
element_atomic_numbers.json ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "1": ["H", "水素 (Hydrogen)"],
3
+ "2": ["He", "ヘリウム (Helium)"],
4
+ "3": ["Li", "リチウム (Lithium)"],
5
+ "4": ["Be", "ベリリウム (Beryllium)"],
6
+ "5": ["B", "ホウ素 (Boron)"],
7
+ "6": ["C", "炭素 (Carbon)"],
8
+ "7": ["N", "窒素 (Nitrogen)"],
9
+ "8": ["O", "酸素 (Oxygen)"],
10
+ "9": ["F", "フッ素 (Fluorine)"],
11
+ "10": ["Na", "ナトリウム (Sodium)"],
12
+ "11": ["Al", "アルミニウム (Aluminium)"],
13
+ "12": ["Si", "ケイ素 (Silicon)"],
14
+ "13": ["P", "リン (Phosphorus)"],
15
+ "14": ["S", "硫黄 (Sulfur)"],
16
+ "15": ["Cl", "塩素 (Chlorine)"],
17
+ "16": ["K", "カリウム (Potassium)"],
18
+ "17": ["Ti", "チタン (Titanium)"],
19
+ "18": ["Cr", "クロム (Chromium)"],
20
+ "19": ["Mn", "マンガン (Manganese)"],
21
+ "20": ["Fe", "鉄 (Iron)"],
22
+ "21": ["Cu", "銅 (Copper)"],
23
+ "22": ["Zn", "亜鉛 (Zinc)"],
24
+ "23": ["As", "ヒ素 (Arsenic)"],
25
+ "24": ["Se", "セレン (Selenium)"],
26
+ "25": ["Br", "臭素 (Bromine)"],
27
+ "26": ["Nb", "ニオブ (Niobium)"],
28
+ "27": ["Mo", "モリブデン (Molybdenum)"],
29
+ "28": ["Ag", "銀 (Silver)"],
30
+ "29": ["Sn", "スズ (Tin)"],
31
+ "30": ["Sb", "アンチモン (Antimony)"]
32
+ }
element_outer_electrons.json ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "水素": 1,
3
+ "ヘリウム": 2,
4
+ "リチウム": 1,
5
+ "ベリリウム": 2,
6
+ "ホウ素": 3,
7
+ "炭素": 4,
8
+ "窒素": 5,
9
+ "酸素": 6,
10
+ "フッ素": 7,
11
+ "アルゴン": 8,
12
+ "クリプトン": 8,
13
+ "キセノン": 8,
14
+ "ナトリウム": 1,
15
+ "マグネシウム": 2,
16
+ "アルミニウム": 3,
17
+ "ケイ素": 4,
18
+ "リン": 5,
19
+ "硫黄": 6,
20
+ "塩素": 7,
21
+ "カリウム": 1,
22
+ "カルシウム": 2
23
+ }
outerElectronFl.py CHANGED
@@ -1,138 +1,42 @@
1
  from flask import Flask, render_template, request, session, redirect, url_for
 
2
  import random
3
 
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
- # 首都のデータを辞書に格納する
41
- capitals = {
42
- 'アルバニア': 'ティラナ',
43
- 'アンドラ': 'アンドラ・ラ・ベリャ',
44
- 'オーストリア': 'ウィーン',
45
- 'ベラルーシ': 'ミンスク',
46
- 'ベルギー': 'ブリュッセル',
47
- 'ボスニア・ヘルツェゴビナ': 'サライェヴォ',
48
- 'ブルガリア': 'ソフィア',
49
- 'クロアチア': 'ザグレブ',
50
- 'チェコ': 'プラハ',
51
- 'デンマーク': 'コペンハーゲン',
52
- 'エストニア': 'タリン',
53
- 'フィンランド': 'ヘルシンキ',
54
- 'フランス': 'パリ',
55
- 'ドイツ': 'ベルリン',
56
- 'ギリシャ': 'アテネ',
57
- 'ハンガリー': 'ブダペスト',
58
- 'アイスランド': 'レイキャヴィーク',
59
- 'アイルランド': 'ダブリン',
60
- 'イタリア': 'ローマ',
61
- 'ラトビア': 'リガ',
62
- 'リヒテンシュタイン': 'ファドゥーツ',
63
- 'リトアニア': 'ヴィリニュス',
64
- 'ルクセンブルク': 'ルクセンブルク',
65
- 'マルタ': 'バレッタ',
66
- 'モルドバ': 'キシナウ',
67
- 'モナコ': 'モナコ',
68
- 'モンテネグロ': 'ポドゴリツァ',
69
- 'オランダ': 'アムステルダム',
70
- '北マケドニア': 'スコピエ',
71
- 'ノルウェー': 'オスロ',
72
- 'ポーランド': 'ワルシャワ',
73
- 'ポルトガル': 'リスボン',
74
- 'ルーマニア': 'ブカレスト',
75
- 'ロシア': 'モスクワ',
76
- 'サンマリノ': 'サンマリノ',
77
- 'セルビア': 'ベオグラード',
78
- 'スロバキア': 'ブラチスラヴァ',
79
- 'スロベニア': 'リュブリャナ',
80
- 'スペイン': 'マドリード',
81
- 'スウェーデン': 'ストックホルム',
82
- 'スイス': 'ベルン',
83
- 'ウクライナ': 'キーウ',
84
- 'イギリス': 'ロンドン',
85
- 'バチカン': 'バチカン',
86
- 'アルメニア': 'エレバン',
87
- 'アゼルバイジャン': 'バクー',
88
- 'キプロス': 'ニコシア',
89
- 'ジョージア': 'トビリシ',
90
- 'イスラエル': 'エルサレム',
91
- 'カザフスタン': 'アスタナ',
92
- 'トルコ': 'アンカラ',
93
- "エチオピア": "アディスアベバ",
94
- }
95
- element_outer_electrons: dict[str, int] = {
96
- "水素": 1,
97
- "ヘリウム": 2,
98
- "リチウム": 1,
99
- "ベリリウム": 2,
100
- "ホウ素": 3,
101
- "炭素": 4,
102
- "窒素": 5,
103
- "酸素": 6,
104
- "フッ素": 7,
105
- "アルゴン": 8,
106
- "クリプトン": 8,
107
- "キセノン": 8,
108
- "ナトリウム": 1,
109
- "マグネシウム": 2,
110
- "アルミニウム": 3,
111
- "ケイ素": 4,
112
- "リン": 5,
113
- "硫黄": 6,
114
- "塩素": 7,
115
- "カリウム": 1,
116
- "カルシウム": 2,
117
- # 他の元素も追加可能
118
- }
119
 
120
  # ランダムな国名とその首都を取得する関数
121
  def get_random_country():
122
  country = random.choice(list(capitals.keys()))
123
  return country, capitals[country]
124
 
 
125
  # 初期の問題を設定する
126
  current_country, current_capital = get_random_country()
127
 
 
128
  @app.route('/')
129
  def index():
130
- return render_template('quiz_index')
 
131
 
132
  @app.route('/quiz_capital', methods=['GET', 'POST'])
133
  def quiz_capital():
134
  global current_country, current_capital
135
-
136
  result = None
137
 
138
  if request.method == 'POST':
@@ -141,21 +45,23 @@ def quiz_capital():
141
  result = '正解です!'
142
  else:
143
  result = '不正解です。正解は{}です。'.format(current_capital)
144
-
145
  return render_template('quiz_capital.html', element=current_country, result=result)
146
 
 
147
  @app.route('/next_capital', methods=['POST'])
148
  def next_question_capital():
149
  global current_country, current_capital
150
  current_country, current_capital = get_random_country()
151
  return redirect(url_for('quiz_capital'))
152
 
 
153
  @app.route('/quiz_element', methods=['GET', 'POST'])
154
  def quiz_element():
155
  # セッションに元素がない場合はランダムに選択
156
  if "element" not in session:
157
  session["element"] = random.choice(list(element_outer_electrons.keys()))
158
-
159
  if request.method == "POST":
160
  user_input = int(request.form["user_input"])
161
  correct_answer = element_outer_electrons[session["element"]]
@@ -167,25 +73,35 @@ def quiz_element():
167
 
168
  return render_template("quiz_element.html", element=session["element"], result=None)
169
 
 
170
  @app.route("/next_element", methods=["POST"])
171
  def next_question_element():
172
  # 次の問題をセッションに設定し、リダイレクト
173
  session["element"] = random.choice(list(element_outer_electrons.keys()))
174
  return redirect(url_for("quiz_element"))
175
 
 
176
  @app.route('/quiz_element2num', methods=['GET', 'POST'])
177
  def quiz_element2num():
178
  # セッションに元素がない場合はランダムに選択
179
  if "element" not in session:
180
- session["element"] = random.choice(list(element_atomic_numbers.values()))[1]
181
-
182
  if request.method == "POST":
183
  user_input = int(request.form["user_input"])
184
- correct_answer = [key for key, value in element_atomic_numbers.items() if value[1] == session["element"]][0]
 
 
 
 
 
 
 
185
  if user_input == correct_answer:
186
  result = "正解です!"
187
  else:
188
  result = f"残念!正解は {correct_answer} でした。"
 
189
  return render_template("quiz_element2num.html", element=session["element"], result=result)
190
 
191
  return render_template("quiz_element2num.html", element=session["element"], result=None)
@@ -196,5 +112,6 @@ def next_question_element2num():
196
  session["element"] = random.choice(list(element_atomic_numbers.values()))[1]
197
  return redirect(url_for("quiz_element2num"))
198
 
 
199
  if __name__ == '__main__':
200
  app.run(debug=True, port=7860)
 
1
  from flask import Flask, render_template, request, session, redirect, url_for
2
+ import json
3
  import random
4
 
5
  app = Flask(__name__)
6
  app.secret_key = "your_secret_key_here"
7
 
8
+ # JSONファイルから元素と原子番号の対応関係を読み込む
9
+ with open("element_atomic_numbers.json", "r", encoding="utf-8") as f:
10
+ element_atomic_numbers = json.load(f)
11
+
12
+ # JSONファイルから首都のデータを読み込む
13
+ with open("capitals.json", "r", encoding="utf-8") as f:
14
+ capitals = json.load(f)
15
+
16
+ # element_outer_electrons
17
+ with open("element_outer_electrons.json", "r", encoding="utf-8") as f:
18
+ element_outer_electrons = json.load(f)
19
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  # ランダムな国名とその首都を取得する関数
22
  def get_random_country():
23
  country = random.choice(list(capitals.keys()))
24
  return country, capitals[country]
25
 
26
+
27
  # 初期の問題を設定する
28
  current_country, current_capital = get_random_country()
29
 
30
+
31
  @app.route('/')
32
  def index():
33
+ return render_template('quiz_index.html')
34
+
35
 
36
  @app.route('/quiz_capital', methods=['GET', 'POST'])
37
  def quiz_capital():
38
  global current_country, current_capital
39
+
40
  result = None
41
 
42
  if request.method == 'POST':
 
45
  result = '正解です!'
46
  else:
47
  result = '不正解です。正解は{}です。'.format(current_capital)
48
+
49
  return render_template('quiz_capital.html', element=current_country, result=result)
50
 
51
+
52
  @app.route('/next_capital', methods=['POST'])
53
  def next_question_capital():
54
  global current_country, current_capital
55
  current_country, current_capital = get_random_country()
56
  return redirect(url_for('quiz_capital'))
57
 
58
+
59
  @app.route('/quiz_element', methods=['GET', 'POST'])
60
  def quiz_element():
61
  # セッションに元素がない場合はランダムに選択
62
  if "element" not in session:
63
  session["element"] = random.choice(list(element_outer_electrons.keys()))
64
+
65
  if request.method == "POST":
66
  user_input = int(request.form["user_input"])
67
  correct_answer = element_outer_electrons[session["element"]]
 
73
 
74
  return render_template("quiz_element.html", element=session["element"], result=None)
75
 
76
+
77
  @app.route("/next_element", methods=["POST"])
78
  def next_question_element():
79
  # 次の問題をセッションに設定し、リダイレクト
80
  session["element"] = random.choice(list(element_outer_electrons.keys()))
81
  return redirect(url_for("quiz_element"))
82
 
83
+
84
  @app.route('/quiz_element2num', methods=['GET', 'POST'])
85
  def quiz_element2num():
86
  # セッションに元素がない場合はランダムに選択
87
  if "element" not in session:
88
+ session["element"] = random.choice(list(element_atomic_numbers.values()))[0]
89
+
90
  if request.method == "POST":
91
  user_input = int(request.form["user_input"])
92
+ correct_answer = [key for key, value in element_atomic_numbers.items() if value[1] == session["element"]]
93
+
94
+ if correct_answer:
95
+ correct_answer = correct_answer[0]
96
+ else:
97
+ # Handle the case where no correct answer is found
98
+ correct_answer = "No matching element found"
99
+
100
  if user_input == correct_answer:
101
  result = "正解です!"
102
  else:
103
  result = f"残念!正解は {correct_answer} でした。"
104
+
105
  return render_template("quiz_element2num.html", element=session["element"], result=result)
106
 
107
  return render_template("quiz_element2num.html", element=session["element"], result=None)
 
112
  session["element"] = random.choice(list(element_atomic_numbers.values()))[1]
113
  return redirect(url_for("quiz_element2num"))
114
 
115
+
116
  if __name__ == '__main__':
117
  app.run(debug=True, port=7860)