From Test-Scratch-Wiki
Scratch contains the resources available for creating a question/answer system. This system can be used for one to be "quizzed", or to repetitively answer automated questions. This tutorial shows various methods on how to create a question system. For each method, the询问 () 并等待 block is used to ask questions and input answers.
Simple Method
This method can become lengthy in scripting, repetitive, and orderly, but still accomplishes a simple question system. The script tells the sprite to ask a question, detect if it is right or wrong, and play a sound according to the outcome. This is a simple way to program a quiz game.
當 @greenflag 被點擊 詢問 [What is 1+1?] 並等待 如果 <(詢問的答案) = [2]> 那麼 播放音效 [correct! v] 到底 變數 [correct v] 改變 (1) 播放音效 [wrong v] 到底 end . . .//repeat the above script with different questions for any desired amount of time
List Method
The next method continuously picks a random question to ask, with questions and answers added to certain lists. The list storage makes adding questions and answers quicker. Each item in the list "questions" must directly correspond to the same item in "answers". Further methods can be used to group questions and implement other functions for various purposes. For the following tutorial, assume the following:
- "questions" is the 清单 which contains each question
- "answers" is the list which contains the corresponding answers to the questions in the list above
- "item#" is a 变量 used to determine the current question one can answer
當 @greenflag 被點擊 重複無限次 變數 [item# v] 設為 (隨機取數 (1) 到 (字串長度\( [questions v)) //picks a random question] \))) 詢問 (清單第 (item#) 項項目\( [questions v] \) :: list) 並等待 // asks he question and waits for the response 如果 <(詢問的答案) = (清單第 (item#) 項項目\( [answers v] \) :: list)> 那麼 播放音效 [correct! v] 到底 // notifies the viewer that the answer is correct 播放音效 [wrong v] 到底 // notifies the viewer that the answer is incorrect 說出 (清單第 (item#) 項項目\( [answers v] \) :: list) (1) 秒 // used to display what the correct answer was end // if the answer is correct end
Group Method
This method is much like the List Method of coding a quiz, but the Grouping Method can be used to group questions and repetitively ask the specified group of questions until a condition is reached. For example, if there are twenty questions, this method can be used to ask four of those questions in the group until they are known very well, and then the system will select a new group. For this method, assume the additional following:
- "current questions" is the list which contains the current group of questions
- "current answers" is the list which contains the current group of corresponding answers
- "correct" is the variable used to determine how many questions of a specific group have been correct
當 @greenflag 被點擊 重複無限次 刪除第 (全部 v) 項 \( [current questions v] \) // clears the current group's questions 刪除第 (全部 v) 項 \( [current answers v] \) // clears the current group's answers 變數 [correct v] 設為 (0) // resets the amount if correct answers for the new group 重複 ([ceiling v] of ((清單 [questions v] 的項目數 :: list) / (5)) //each group contains 1/5 of the total questions) 次 變數 [item# v] 設為 (隨機取數 (1) 到 (清單 [questions v] 的項目數 :: list)) 新增項目 (清單第 (item#) 項項目\( [questions v] \) :: list) \( [current questions v] \) // adds a questions to a group 新增項目 (清單第 (item#) 項項目\( [answers v] \) :: list) \( [current answers v] \) // adds the corresponding answer end 重複直到 <(correct) = [15]> 變數 [item# v] 設為 (隨機取數 (1) 到 (字串長度\( [current questions v)) //picks a random question] \))) 詢問 (清單第 (item#) 項項目\( [current questions v] \) :: list) 並等待 // asks he question and waits for the response 如果 <(詢問的答案) = (清單第 (item#) 項項目\( [current answers v] \) :: list)> 那麼 播放音效 [correct! v] 到底 // notifies the viewer that the answer is correct 變數 [correct v] 改變 (1) 播放音效 [wrong v] 到底 // notifies the viewer that the answer is incorrect 說出 (清單第 (item#) 項項目\( [current answers v] \) :: list) (1) 秒 // used to display what the correct answer was end // if the answer is correct end // "15" can be changed to the desired amount needed correct each group end
Mathematical Method
This method is used in a math quiz in a way very much like the list method, but takes use of the Operators blocks to make several possibilities without needing to list them. Take, for example, randomly generated addition questions involving addends from 1 to 20. For this method, assume these variables:
- "number1" is the first added to the question
- "number2" is the second added in the question
- "expect_answer" is the expected answer of the generated question
當 @greenflag 被點擊 重複無限次 變數 [number1 v] 設為 (隨機取數 (1) 到 (20)) 變數 [number2 v] 設為 (隨機取數 (1) 到 (20)) // generates two random integers from 1 to 20 變數 [expect_answer v] 隱藏 // hides the answer if it is still showing 變數 [expect_answer v] 設為 ((number1) + (number2)) // calculates the result 詢問 (字串組合 (number1) 和 (字串組合 [ + ] 和 (number2))) 並等待 // asks the question 如果 <(詢問的答案) = (expect_answer)> 那麼 播放音效 [correct v] 到底 // notifies the viewer that the answer is correct 播放音效 [wrong v] // notifies the viewer that the answer is incorrect 變數 [expect_answer v] 顯示 // tells viewer what the correct answer was 等待 (4) 秒 // assures that the viewer has enough time to react before the variable is hidden again by the next loop end // if the answer is correct end