質問編集履歴
1
英語での実際の質問と回答の掲載
title
CHANGED
File without changes
|
body
CHANGED
@@ -39,4 +39,59 @@
|
|
39
39
|
for post in posts:
|
40
40
|
print(f"{post['id']} / {post['title']}")
|
41
41
|
```
|
42
|
-
よろしくお願いいたします。
|
42
|
+
よろしくお願いいたします。
|
43
|
+
|
44
|
+
---
|
45
|
+
みなさま、ありがとうございます。言葉足らずな部分が多くあり、申し訳ありません。
|
46
|
+
講座の内容はPythonのFlaskを使ってちょっとしたデータを表示させるものです。
|
47
|
+
今回のコードはその内容のデータ取得部分となります。
|
48
|
+
|
49
|
+
**前回の英語での質問は、この講座とは異なる場所での質問でした**ので、
|
50
|
+
ここに掲載しても仕方ないと思っていましたが、一応掲載することにします。
|
51
|
+
余計混乱する可能性もありますが、その時はすみません????????♂️
|
52
|
+
|
53
|
+
質問内容は同じで、なんでクラスから作る必要があるのか?というものです。
|
54
|
+
|
55
|
+
### 質問内容
|
56
|
+
|
57
|
+
Why do we have to make Question object? ????
|
58
|
+
|
59
|
+
I didn't know why I had to make Question object from question_data.
|
60
|
+
It usually works by doing this, right?
|
61
|
+
|
62
|
+
```Python
|
63
|
+
|
64
|
+
question = QuizBrain(question_data)
|
65
|
+
```
|
66
|
+
|
67
|
+
|
68
|
+
```python
|
69
|
+
|
70
|
+
def next_question(self):
|
71
|
+
current_question = self.question_list[self.question_number]
|
72
|
+
self.question_number += 1
|
73
|
+
user_answer = input(f"Q.{self.question_number}: {current_question['text']} (True/False)?: ")
|
74
|
+
self.check_answer(user_answer, current_question['answer'])
|
75
|
+
```
|
76
|
+
|
77
|
+
|
78
|
+
Of course, some code had to be modified like this.
|
79
|
+
```ここに言語を入力
|
80
|
+
current_question.text → current_question['text']
|
81
|
+
```
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
Please, can anyone tell me why this process was necessary? ????♂️
|
86
|
+
### 頂いた返信
|
87
|
+
We have defined the QuizBrain class to expect a list of questions when you first create a new object. You can see that from the __init__ function.
|
88
|
+
|
89
|
+
Therefore when you created your object called "question", it must have a list of questions. In this case "question_data" is the list of questions and answers for your "question" object.
|
90
|
+
|
91
|
+
I hope that makes sense.
|
92
|
+
### 私の解釈
|
93
|
+
もともと最初に新しいオブジェクトを作るときに、質問リストが帰るように定義してたよね?
|
94
|
+
だからquestionオブジェクト作ったら質問リスト持ってないと駄目なんだよ。
|
95
|
+
|
96
|
+
という感じで捉えてますが、それでもいまいち理解できませんでした。
|
97
|
+
ので、今回また同じようなクラスからのオブジェクト作成ではここで質問させてい頂いたというわけです。
|