예제 #1
0
def checkStack(q,correct):
    stack=getStack(input.get_input(q))
    response = ""
    errors = 0
    grade = 0
    if(stack == correct):
        grade=100
        feedback.set_problem_result("success", q)
        feedback.set_problem_feedback(response, q)
        return grade
    else:
        if not (stack.startswith( correct[0:1] ) ):
            response += "The top-label of your stack is incorrect.\n"

        if not (stack.endswith( correct[-2:] ) ):
            response += "The bottom label of your stack is incorrect.\n"

        clist=correct.split(':')
        slist=stack.split(':')
        if len(slist) > len(clist):
            response += "Your answer contains more labels in its stack than the correct one.\n"
        if len(slist) < len(clist):
            response += "Your answer contains fewer labels in its stack than the correct one.\n"
            
        feedback.set_problem_result("failed", q)
        response += "Your answer to this question is incorrect.\n"
        feedback.set_problem_feedback(response, q)
        return grade
예제 #2
0
def checkSinglePath(q, correct):
    path = getPath(input.get_input(q))
    response = ""
    errors = 0
    grade = 0
    if (path == correct):
        grade = 100
        feedback.set_problem_result("success", q)
        feedback.set_problem_feedback(response, q)
        return grade
    else:
        if not (path.startswith(correct[0:1])):
            response += "Your answer does not start with {}\n".format(
                correct[0:1])

        if not (path.endswith(correct[-2:])):
            response += "Your answer does not end with {}\n".format(
                correct[-2:])
        if (',' in path):
            response += "There is only one path from this router.\n"

        feedback.set_problem_result("failed", q)
        response += "Your answer to this question is incorrect. There is only one path from this router to the destination.\n"
        feedback.set_problem_feedback(response, q)
        return grade
예제 #3
0
def checkNPaths(q, correct):
    path = getPath(input.get_input(q))
    list = path.split(',')
    clist = correct.split(',')
    errors = 0
    grade = 0
    response = ""

    if (len(list) != len(clist)):
        feedback.set_problem_result("failed", q)
        response += "Your answer to this question is incorrect. There are {} paths from this router.\n".format(
            len(clist))
        feedback.set_problem_feedback(response, q)
        return 0

    for l in clist:
        if not (l in list):
            feedback.set_problem_result("failed", q)
            response += "Your answer to this question is incorrect.\n"
            feedback.set_problem_feedback(response, q)
            return 0

    feedback.set_problem_result("success", q)
    feedback.set_problem_feedback(response, "q1")
    return 100
예제 #4
0
    simp_answer = "("
    for el in answer:
        if el in "-.,1234567890":
            simp_answer += el
    simp_answer += ")"

    return simp_answer == correction


answer = input.get_input(
    "q1")  #Remplacez tous les 'q1' par l'ID du sous-problème
grade = 0
check = is_coordinates(answer)

if check != True:  #Renvoie un feedback personnalisé en fonction des erreurs rencontrées
    feedback.set_problem_result("failed", "q1")  #Ici
    if check == "parenthese":
        feedback.set_problem_feedback(
            "Votre réponse doit contenir des parenthèses pour délimiter le point",
            "q1")  #Ici
    if check == "lettre":
        feedback.set_problem_feedback(
            "Votre réponse ne doit contenir que des chiffres", "q1")  #Ici
    if check == "separateur":
        feedback.set_problem_feedback(
            "Les coordonnées doivent être séparées par une virgule",
            "q1")  #Ici

elif check == True:
    if is_correct(
            answer, "(2,2)"
예제 #5
0
            "* {desc}\n\n  => réussi ({weight}/{weight}) pts)\n\n".format(
                **test) + ("  Info: {}\n\n".format(" — ".join(
                    test['info_msgs'])) if test['info_msgs'] else '\n'),
            test['pid'], True)
        tests_result[test['pid']] = True if tests_result.get(
            test['pid'], True) else False
    else:
        feedback.set_problem_feedback(
            "* {desc}\n\n  => échoué (0/{weight}) pts)\n\n".format(**test) +
            ("  Info: {}\n\n".format(" — ".join(test['info_msgs']))
             if test['info_msgs'] else '\n'), test['pid'], True)
        tests_result[test['pid']] = False

for pid, result in tests_result.items():
    if result:
        feedback.set_problem_result("success", pid)
    else:
        feedback.set_problem_result("failed", pid)

with open("../task.yaml", 'r') as stream:
    problems = yaml.load(stream)['problems']

    for name, meta in problems.items():
        if meta['type'] == 'match':
            answer = input.get_input(name)
            if answer == meta['answer']:
                feedback.set_problem_result("success", name)
                feedback.set_problem_feedback(
                    "Votre réponse est correcte. (1/1 pts)", name, True)
                score += 1
            else:
def set_problem_result(problem_id, result, fb):
    """Set the result and the feedback to a problem."""

    feedback.set_problem_result(result, problem_id)
    feedback.set_problem_feedback(fb, problem_id)