استورد answers.aspl بسم answers. سجل Question { prompt: نص, answer: ص64 } دالة summary(label: نص, correct: ص64, answered: ص64, total: ص64) -> وحدة { اطبع(label + ". Correct: " + نسق_ص64(correct) + "; answered: " + نسق_ص64(answered) + "; total: " + نسق_ص64(total) + ".\n"). } دالة ابدأ_الرئيسية() -> ص64 { دع questions: قائمة = [ Question { prompt: "2 + 3?", answer: 5 }, Question { prompt: "9 - 4?", answer: 5 }, Question { prompt: "3 * 4?", answer: 12 }, Question { prompt: "12 / 3?", answer: 4 }, Question { prompt: "7 + 8?", answer: 15 } ]. دع total: ص64 = طول(questions). متغير index: ص64 = 0. متغير answered: ص64 = 0. متغير correct: ص64 = 0. اطبع("Quiz: " + نسق_ص64(total) + " questions. Type q to stop.\n"). طالما (index < total) { دع question: Question = questions[index]. اطبع("Question " + نسق_ص64(index + 1) + "/" + نسق_ص64(total) + ": " + question::prompt + " "). دع line: نص = اقرأ_سطر(). إذا (line يطابق "q") { summary("Stopped early", correct, answered, total). أرجع 0. } دع parsed: نتيجة<ص64> = حلل_ص64(line). إذا (parsed::نجاح) { إذا (answers::is_correct(question::answer, parsed::قيمة)) { اطبع("Correct.\n"). correct = correct + 1. } وإلا { اطبع("Wrong. Expected " + نسق_ص64(question::answer) + ".\n"). } answered = answered + 1. index = index + 1. } وإلا { اطبع("Retry: " + parsed::الخطأ::الرمز + ". Use ASCII digits, for example 5, or q.\n"). } } summary("Completed", correct, answered, total). أرجع 0. }