MATLAB Answers

Make a quiz in matlab

82 views (last 30 days)
Eddy Iswardi
Eddy Iswardi on 6 Jun 2020
Commented: relamanma on 7 Oct 2020
I have questions for my quiz like this example
questions = {'How many earth? '
'Is 7 a prime number? '
'How much water in glass? ' }
How to add the answer key?, my answer key is
How many earth = one
Is 7 a prime number = yes
How much water in glass = Not identify
the answer key is used to give a correction for the answer.
Example : when I answer 'no' for 'Is 7 a prime number?', the statement 'incorrect' will apper under the answer, but if I answer 'yes', the statement will be 'correct'

Accepted Answer

KSSV
KSSV on 6 Jun 2020
questions = {'How many earth? '
'Is 7 a prime number? '
'How much water in glass? ' } ;
answers = {'one' , 'yes', 'Not identify'} ;
N = length(questions) ;
prompt = 'Answer: ' ;
for i = 1:N
fprintf(questions{i},'%s') ;
user_answer = input(prompt, 's') ;
if strcmpi(answers{i},user_answer) % compare answer
fprintf("Correct\n",'%s')
else
fprintf("Incorrect\n",'%s')
end
end
  3 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!