8
\$\begingroup\$

A fun programming exercise is to write a program that quizzes the user from a set list of questions and answers. However, this task goes a level beyond that.

Your task

  • Write a program/func/etc. that takes two lists: A list of questions and a list of answers.
  • Output a program that quizzes the user.
  • The output program should ask each question on a separate line, which each question with a colon and space at the end like, What is 2+2:.
  • After the user answers all the questions, output a newline, and then one on each line, questions correct, questions wrong, and percentage calculation (rounded to 2 decimal places) as such (the brackets are user input):


What is the meaning of life, the universe, and everything: <42>
Am I awesome(Yes/No): <No>
What is 2+2: <4>

Number Correct: 2
Number Wrong: 1
Score: 2 / 3 * 100 = 66.67%

Scoring

  • You are scored on the size of your compiler program.
  • This is so shortes code in bytes wins!
  • Bonus: Score *.9 if you implement a flag in your compiler that makes the output program randomize question order.
\$\endgroup\$
3
  • \$\begingroup\$ If none are correct, or all are wrong, should that line be skipped? \$\endgroup\$
    – Ypnypn
    Nov 25, 2015 at 5:28
  • \$\begingroup\$ @Ypnypn no, they should always be there. \$\endgroup\$
    – Maltysen
    Nov 25, 2015 at 12:04
  • \$\begingroup\$ Can I use JS's prompt and alert for I/O? (As in, prompt each question with the text <question>: , then alert each line of the result separately) \$\endgroup\$ Oct 24, 2020 at 17:11

1 Answer 1

3
\$\begingroup\$

CJam, 105 99 bytes

{{": "+ol}%.=_:+\,:LX$-X$LX$e2Ld/]"
Number Correct: %d
Number Wrong: %d
Score: %d / %d * 100 = %.2f%%"e%}

This defines an anonymous function.

The code is 110 bytes long and qualifies for the × 0.9 randomization bonus.

Test run

$ cat qna.cjam
[
  [
    "42"
    "Yes"
    "4"
  ]

  [
    "What is the meaning of life, the universe, and everything"
    "Am I awesome(Yes/No)"
    "What is 2+2"
  ]
]

{zmrz~{": "+ol}%.=_:+\,:LX$-X$LX$e2Ld/]"
Number Correct: %d
Number Wrong: %d
Score: %d / %d * 100 = %.2f%%"e%}

~

$ cjam qna.cjam
What is 2+2: 4
Am I awesome(Yes/No): No
What is the meaning of life, the universe, and everything: 42

Number Correct: 2
Number Wrong: 1
Score: 2 / 3 * 100 = 66.67%
\$\endgroup\$
2
  • \$\begingroup\$ Wow, this is the longest CJam answer I have ever seen! \$\endgroup\$
    – J Atkin
    Nov 25, 2015 at 3:13
  • \$\begingroup\$ Not even close. :) \$\endgroup\$
    – Dennis
    Nov 25, 2015 at 3:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.