After loading the code file submitted by the student, you can evaluate the submission based on specific conditions.
The example below is a grading code for a practice that requires creating a haiku using the print() function three times.
After loading the file written by the student (main.py), the code checks if the print() function is used three times to grade the practice.
import osimport subprocessimport syssys.path.append(os.getcwd())from grader_elice_utils import EliceUtils # isort:skipelice_utils =EliceUtils()elice_utils.secure_init()try: total_score =0# Code to check if the print() function is used three times or more count =0withopen("main.py")as ans: datafile = ans.readlines()for line in datafile:if'print'in line: count +=1if count >=3: total_score +=100 elice_utils.secure_send_grader('✅ Correct! You have created a beautiful haiku using the print() function! \n')else: elice_utils.secure_send_grader('❌ Incorrect! Try using the print() function three times to create a haiku.\n')# Sending the final practice score total_score =int(total_score) elice_utils.secure_send_score(total_score)exceptExceptionas err: elice_utils.secure_send_grader('An error occurred while grading. Please check if your code runs correctly.\n') elice_utils.secure_send_score(0) sys.exit(1)