Autograder demo: Adding leading/trailing code

This question defines the files leading_code.py and trailing_code.py to automatically prepend/append code to the student's answer before grading. Adding these files allows one to automatically handle imports, function definitions, etc. The contents of the leading and trailing code files are displayed in the code blocks below.

Complete the function below that computes one iteration of gradient descent: $$ {\bf x}_{n+1} = {\bf x}_n - \alpha \nabla f\left({\bf x}_n\right) $$ Specifically, compute the value of x_new (${\bf x}_{n+1}$) given ${\bf x}_n$, $\alpha$, and $\nabla f\left({\bf x}_n\right)$.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
def f(x):
    return x**2


def df(x):
    return 2 * x


def gradient_descent(x, alpha):
    grad_f = df(x)
1
    return x_new

Correct answer

Student view placeholder

In student views this area is used for assessment and score info.
Tools

Staff information

Question

Title:
Autograder demo: Adding leading/trailing code

Variant

Started at:
2026-09-19 08:00:26 (CDT)
Duration:
0s
Show/Hide answer
{}
History
dec frac
rad deg