This article is the 8th day article of DSL Advent Calendar 2019.
This article may be more of a report for programming educators. Also, I am not trying to criticize a specific person or group, so it would be helpful if you could understand that.
From this year, a lecture called "Introduction to Programming" has started for first-year undergraduate students of all departments of Muroran Institute of Technology. In this class, you will systematically learn programming and data processing using the programming language "Python". The exercise uses the Jupyter Notebook provided by National Institute of Informatics (NII). In addition, one .ipynb of exercises and one assignment is distributed for each lesson so that students can work on the questions in a question-and-answer format.
I participate in the lecture as a TA (Teaching Assistant). I would like to introduce some points that programming beginners who noticed in that process especially stumble when learning Python. I hope that people and faculty members in the same position who have seen this article will find it useful.
I will introduce what kind of mistakes I have made about these and what kind of measures should be taken with examples.
--Full-width space --Enter symbols, parentheses, etc. in full-width and then convert (parentheses → (), etc.)
Full-width input is a common thing for beginners in programming. If there is a double-byte space, an error will occur and the program will not work. Also, note that Python can be easily used as str even if it is a double-byte character. Those who should be especially careful are those who are typing in basic full-width characters. Especially in modern times, there are some people who are not accustomed to keyboard input rather than programming, as it is said to be the smartphone generation. In that case, it is not possible to know the location of the symbol.
--Get used to the PC keyboard --Make a question sentence that does not require full-width input
I think the best solution is to get used to the keyboard. Other than that, it may be better to make the problem itself a problem that does not require full-width input. (For example, all the parts that output Japanese sentences are changed to English)
I often see this mistake.
for i in range(10):
for j in range(10):
print(f'i + j = {i + j}') #error:The indent is out of alignment
Originally, I had to lower the indent with print ()
, but it was not lowered correctly. If it is a double for statement like the above, there is no mistake so much, but it seems that the number of mistakes will increase as the number of nested structures increases, such as the inclusion of conditional branches such as if.
This is promoted by the program copy / paste and jupyter auto-indent function. It seems that many people are stumbling when copying and pasting a program, rather than pulling in another person's program, when designing a problem by using a part of the previous problem and incorporating it into the next problem. For example, if the problem is that only the conditional branch is created in the first question and it is incorporated in the for loop in the second question, the nest structure may be out of order with the auto indent function and it may not work. In addition, I see patterns in which the structure becomes more and more difficult to understand when indentation is taken in multiple spaces.
--Understanding the nesting structure --Tab key to indent --Read the error
I think that these three points will usually work. In Python, unlike C language, loops are controlled by indentation instead of parentheses, so special attention should be paid to the nesting structure. It is becoming important that the order will tell us first the importance of indent Whatever the program. Also, using the Tab key makes the completion function and indentation work a little easier, so I think it is important to teach how to use it early to solve this problem. And reading the error is the best solution, but I think it is essential to understand the structure because it is not possible to know what is wrong or how it is wrong depending on the code.
This is such a mistake.
#pattern 1
a = 1
b = "1"
print(a + b) #error: int +str cannot
print(a + int(b)) # 2
#Pattern 2
a = (1, 2, 3)
b = [1, 2, 3]
a.append(4) #error:Tuples cannot append
b.append(4) # [1, 2, 3, 4]
Pattern 1 is a common one for programming beginners, but I think that you have to be especially careful if you are a programming language that Python is learning for the first time because you declare variables after declaring types in languages other than Python. .. The same is true for pattern 2, where a is a tuple and b is a list, but when you want to add elements to these "arrays", append is used, but if you are a beginner in programming, even if the array is a list, it is a tuple. It seems that it (even in a dictionary) looks almost the same.
--Type confirmation using type () --Clarify the differences in methods and properties for each type --Read the error --Declare types explicitly using the typing module
I don't know the difficult story of the type, so I'm sorry, but it's okay because it's quick to check the type of variables etc. that I basically don't understand in Python with type (). Also, if you understand the difference between types, the above should not happen, so it may be better to spend more time teaching. And since this can also be solved by reading the error, the error display is still great. The rest is about the typing module. This depends on the Python environment, but this usage alone is likely to take about an article, so I will omit a detailed explanation, but using the typing module may make you more aware of the type. ..
It is especially difficult to give an example here, so I would like to propose a little solution. Also, this may be the most important because most of the problems listed above should be solved just by being able to read the error.
--Summary of expected error sentences and their solutions --Get in the habit of searching the Web for the details of the error as it is
I think these two points can be easily done. As long as the content of the error solves the same problem, it is thought that most people often stumble at the same place. Therefore, I think it is good to summarize the expected error contents and the countermeasures in advance. Regarding Web search, programming beginners do not have the habit of googled errors. With Python, most errors can be solved by simply copying the error statement and copying the search results, so it may be easier to make such a habit.
From here, I would like to briefly list what seems to be a mistake caused by using teaching materials and jupyter rather than the cause of the mistake. I think this is a problem that can be easily solved by both the teaching side and the teaching side by understanding the specifications of jupyter.
In the currently provided Jupyter Notebook environment, when cell is executed, green is displayed if there is no error, and red is displayed if there is an error. Basically, there is no problem if all green is displayed, but on the contrary, it may be hindering the progress. For example, in a cell that defines only a function, even if the behavior of the contents is a little strange, no error is displayed, so the cell can be executed without any problem. Therefore, there is a problem that you do not know where to look when an error occurs after performing some processing using that function in the lower cell.
This problem is related to ipynb distributed by my university in the lecture, and it is closely related to the above problem, but the problem is divided into multiple cells and the behavior when executed is strange. .. Please refer to the image below for an example.
If each problem depends on the execution result of the above cell as above, the behavior may be suspicious. In the above example, q3 is asked using the list and function created by q1 and q2, but in reality, it may be a more complicated process or problem. What's wrong with this is that the cell execution order is only assumed to be from top to bottom. As a result, if you execute it again, the result may be different from the existing output. Also, when the notebook stops responding due to a server error etc., it may be necessary to restart the kernel, but many people only execute it from the middle of the cell. (This is because I don't understand that all variables etc. are reset by rebooting)
Since the specification of this jupyter is awkward, I think it is safe to combine one problem into one cell to solve this.
I briefly mentioned what I thought when I was doing TA for the introduction to Python programming, but I had the impression that I often stumbled because the teachers did not give enough consideration. I'm tired of writing for too long, so I'm going to put a brush here, but in reality, I'm stumbling on a more trivial point, so it's still difficult to teach programming. felt. I hope this article helps someone.
Recommended Posts