pythonwhat/checks/has_funcs.py
def has_chosen(state, correct, msgs):
    """Test multiple choice exercise.

    Test for a MultipleChoiceExercise. The correct answer (as an integer) and feedback messages
    are passed to this function.

    Args:
        correct (int): the index of the correct answer (should be an instruction). Starts at 1.
        msgs (list(str)): a list containing all feedback messages belonging to each choice of the
                          student. The list should have the same length as the number of options.
    """
    if not issubclass(type(correct), int):
        raise InstructorError(
            "Inside `has_chosen()`, the argument `correct` should be an integer."
        )

    student_process = state.student_process
    if not isDefinedInProcess(MC_VAR_NAME, student_process):
        raise InstructorError("Option not available in the student process")
    else:
        selected_option = getOptionFromProcess(student_process, MC_VAR_NAME)
        if not issubclass(type(selected_option), int):
            raise InstructorError("selected_option should be an integer")

        if selected_option < 1 or correct < 1:
            raise InstructorError(
                "selected_option and correct should be greater than zero"
            )

        if selected_option > len(msgs) or correct > len(msgs):
            raise InstructorError("there are not enough feedback messages defined")

        feedback_msg = msgs[selected_option - 1]

        state.reporter.success_msg = msgs[correct - 1]

        state.do_test(EqualTest(selected_option, correct, feedback_msg))
def has_chosen(state, correct, msgs):
    """Test multiple choice exercise.

    Test for a MultipleChoiceExercise. The correct answer (as an integer) and feedback messages
    are passed to this function.

    Args:
        correct (int): the index of the correct answer (should be an instruction). Starts at 1.
        msgs (list(str)): a list containing all feedback messages belonging to each choice of the
                          student. The list should have the same length as the number of options.
    """
    if not issubclass(type(correct), int):
        raise InstructorError(
            "Inside `has_chosen()`, the argument `correct` should be an integer."
        )

    student_process = state.student_process
    if not isDefinedInProcess(MC_VAR_NAME, student_process):
        raise InstructorError("Option not available in the student process")
    else:
        selected_option = getOptionFromProcess(student_process, MC_VAR_NAME)
        if not issubclass(type(selected_option), int):
            raise InstructorError("selected_option should be an integer")

        if selected_option < 1 or correct < 1:
            raise InstructorError(
                "selected_option and correct should be greater than zero"
            )

        if selected_option > len(msgs) or correct > len(msgs):
            raise InstructorError("there are not enough feedback messages defined")

        feedback_msg = msgs[selected_option - 1]

        state.reporter.success_msg = msgs[correct - 1]

        state.do_test(EqualTest(selected_option, correct, feedback_msg))
def has_chosen ( state , correct , msgs ) : if not issubclass ( type ( correct ) , int ) : raise InstructorError ( "Inside `has_chosen()`, the argument `correct` should be an integer." ) student_process = state . student_process if not isDefinedInProcess ( MC_VAR_NAME , student_process ) : raise InstructorError ( "Option not available in the student process" ) else : selected_option = getOptionFromProcess ( student_process , MC_VAR_NAME ) if not issubclass ( type ( selected_option ) , int ) : raise InstructorError ( "selected_option should be an integer" ) if selected_option < 1 or correct < 1 : raise InstructorError ( "selected_option and correct should be greater than zero" ) if selected_option > len ( msgs ) or correct > len ( msgs ) : raise InstructorError ( "there are not enough feedback messages defined" ) feedback_msg = msgs [ selected_option - 1 ] state . reporter . success_msg = msgs [ correct - 1 ] state . do_test ( EqualTest ( selected_option , correct , feedback_msg ) )
Test multiple choice exercise.

    Test for a MultipleChoiceExercise. The correct answer (as an integer) and feedback messages
    are passed to this function.

    Args:
        correct (int): the index of the correct answer (should be an instruction). Starts at 1.
        msgs (list(str)): a list containing all feedback messages belonging to each choice of the
                          student. The list should have the same length as the number of options.
Test multiple choice exercise .