blob: 6d6b95f12babf075d7889bb38eaa35ed795c5600 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
What is wrong with the following program that prints all divisors?
\vspace{0.5cm}
\begin{Verbatim}[xleftmargin=6mm]
\textbf{def} divisors(n):
\textbf{for} d \textbf{in} range(1,\red{n}):
\textbf{if} n % d == 0:
print(d)
\end{Verbatim}
\vspace{0.5cm}
Answer: \texttt{range(1,n)} only generates values up to \texttt{n-1}, so \texttt{n} is not printed.
Instead, \texttt{range(1,n+1)} should be used.
\vspace{1cm}
An experienced teacher can spot such errors easily, without having to run the program. Can we discover that knowledge automatically?
More specifically:
\vspace{1cm}
\begin{itemize}
\item How do we encode distinctive program features?
\item Can we discern which features are relevant to some error or solution?
\end{itemize}
\vspace{1cm}
We address these questions by using abstract-syntax-tree (AST) patterns to encode program features, and machine-learned rules to discover common errors and solution strategies for beginner Python programs.
|