You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: data/part-11/3-recursion.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -146,7 +146,7 @@ The factorial of 6 is 720
146
146
147
147
If the parameter of the recursive factorial function is 0 or 1, the function returns 1, because this is how the factorial operation is defined. In any other case the function returns the value `n * factorial(n - 1)`, which is the value of its parameter `n` multiplied by the return value of the function call `factorial(n - 1)`.
148
148
149
-
The crucial part here is that the function definition contains a stop condition. If this is met, the recursion ends. In this case that condition is `n < 2`. We know it will be reached eventually, beacuse the value passed as the argument to the function is decreased by one on each level of the recursion.
149
+
The crucial part here is that the function definition contains a stop condition. If this is met, the recursion ends. In this case that condition is `n < 2`. We know it will be reached eventually, because the value passed as the argument to the function is decreased by one on each level of the recursion.
150
150
151
151
The [visualisation tool](http://www.pythontutor.com/visualize.html#mode=edit) can be a great help in making sense of recursive programs.
Copy file name to clipboardExpand all lines: data/part-5/1-more-lists.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -300,7 +300,7 @@ Alan: age 39 years, height 1.78 meters
300
300
301
301
The `for` loop goes through the items in the outer list one by one. That is, each list containing information about a single person is, in turn, assigned to the variable `person`.
302
302
303
-
Lists arent always the best way to present data, such as information about a person. We will soon come across Python _dictionaries_, which are often better suited to such situations.
303
+
Lists aren't always the best way to present data, such as information about a person. We will soon come across Python _dictionaries_, which are often better suited to such situations.
304
304
305
305
## Matrices
306
306
@@ -333,7 +333,7 @@ print(my_matrix)
333
333
334
334
</sample-output>
335
335
336
-
Like any other list, the rows of the matrix can be traversed wth a `for` loop. The following code prints out each row of the matrix on a separate line:
336
+
Like any other list, the rows of the matrix can be traversed with a `for` loop. The following code prints out each row of the matrix on a separate line:
UnboundLocalError: local variable 'oldest' referenced before assignment
297
297
```
298
298
299
-
The reason this happens is that the latter `for` loop is not executed at all, beacuse the file can only be processed once. Once the last line is read, the file handle rests at the end of the file, and the data in the file can no longer be accessed.
299
+
The reason this happens is that the latter `for` loop is not executed at all, because the file can only be processed once. Once the last line is read, the file handle rests at the end of the file, and the data in the file can no longer be accessed.
300
300
301
301
If we want to access the contents in the second `for` loop, we will have to `open` the file a second time:
302
302
@@ -426,7 +426,7 @@ with open("people.csv") as new_file:
426
426
print(last_names)
427
427
```
428
428
429
-
Exectuing this would print out
429
+
Executing this would print out
430
430
431
431
<sample-output>
432
432
@@ -662,7 +662,7 @@ liisa virtanen 3
662
662
663
663
</sample-output>
664
664
665
-
Each completed exercise is counted towards _exercise points_, so that completing at least 10 % of the total exercices awards 1 point, completing at least 20 % awards 2 points, etc. Completing all 40 exercises awards 10 points. The number of points awarded is always an integer number.
665
+
Each completed exercise is counted towards _exercise points_, so that completing at least 10 % of the total exercises awards 1 point, completing at least 20 % awards 2 points, etc. Completing all 40 exercises awards 10 points. The number of points awarded is always an integer number.
666
666
667
667
The final grade for the course is determined based on the sum of exam and exercise points according to the following table:
Copy file name to clipboardExpand all lines: data/part-6/2-writing-files.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -107,7 +107,7 @@ Hi Ada, we hope you enjoy learning Python with us! Best, Mooc.fi Team
107
107
108
108
If you want to append data to the end of a file, instead of overwriting the entire file, you should open the file in append mode with the argument `a`.
109
109
110
-
If the file doesn't yet exist, append mode works exatly like write mode.
110
+
If the file doesn't yet exist, append mode works exactly like write mode.
111
111
112
112
The following program opens the file `new_file.txt` and appends a couple of lines of text to the end:
113
113
@@ -421,7 +421,7 @@ Emily;41;5
421
421
422
422
</sample-data>
423
423
424
-
Notice how each function defined above is relatively simple, and they all have a single responsibility. This is a common and advisable approach when programming larger wholes. The single reponsibility principle makes verifying functionality easier. It also makes it easier to make changes to the program later, and to add new features.
424
+
Notice how each function defined above is relatively simple, and they all have a single responsibility. This is a common and advisable approach when programming larger wholes. The single responsibility principle makes verifying functionality easier. It also makes it easier to make changes to the program later, and to add new features.
425
425
426
426
Say we wanted to add a function for printing out the grade for a single student. We already have a function which determines the student's grade, so we can use this in our new function:
427
427
@@ -449,7 +449,7 @@ If we determine a certain functionality in the program needs fixing, in a well d
449
449
450
450
Let's revisit the course grading project from the previous section.
451
451
452
-
As we left if last time, the program read and processed files containing student information, completed exercises and exam results. We'll add a file containing information about the course. An example of the format of the file:
452
+
As we left it last time, the program read and processed files containing student information, completed exercises and exam results. We'll add a file containing information about the course. An example of the format of the file:
Copy file name to clipboardExpand all lines: data/part-6/3-errors.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ After this section
15
15
16
16
</text-box>
17
17
18
-
The are two basic categories of errors that come up in programming contexts:
18
+
There are two basic categories of errors that come up in programming contexts:
19
19
20
20
1. Syntax errors, which prevent the execution of the program
21
21
2. Runtime errors, which halt the execution
@@ -74,7 +74,7 @@ The `int` function is unable to parse the input string `twenty-three` as a valid
74
74
75
75
Errors that occur while the program is already running are called _exceptions_. It is possible to prepare for exceptions, and handle them so that the execution continues despite them occurring.
76
76
77
-
Exception handling in Python is accomplished with `try` and `except` statements. The idea is that if something within a `try` block causes an exception, Python checks if there is a corresponding `except` block. If such a block exists, it is executed and the program themn continues as if nothing happened.
77
+
Exception handling in Python is accomplished with `try` and `except` statements. The idea is that if something within a `try` block causes an exception, Python checks if there is a corresponding `except` block. If such a block exists, it is executed and the program then continues as if nothing happened.
78
78
79
79
Let's change the above example so that the program is prepared for the `ValueError` exception:
80
80
@@ -99,7 +99,7 @@ This is not a valid age
99
99
100
100
We can use the `try` block to flag that the code within the block may cause an error. In the `except` statement directly after the block the relevant error is mentioned. In the above example we covered only a `ValueError` exception. If the exception had some other cause, the execution would still have halted, despite the `try` and `except` blocks.
101
101
102
-
In the above example, if the error is caught, the value of `age` is set to -1. This is an invalid input value which we have already programmed behaviour for, as the program excpects the age of the user to be greater than 0.
102
+
In the above example, if the error is caught, the value of `age` is set to -1. This is an invalid input value which we have already programmed behaviour for, as the program expects the age of the user to be greater than 0.
103
103
104
104
In the following example we have a function `read_integer`, which asks the user to type in an integer value, but the function is also prepared for invalid input. The function keeps asking for integers until the user types in a valid input value.
105
105
@@ -333,7 +333,7 @@ Invalid parameters in this case include:
Copy file name to clipboardExpand all lines: data/part-7/4-data-processing.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ After this section
16
16
17
17
## Reading CSV files
18
18
19
-
CSV is such a simple format that so far we have accessed the with hand-written code. There is, however, a ready-made module in the Python standard library for working with CSV files: [csv](https://docs.python.org/3/library/csv.html). It works like this:
19
+
CSV is such a simple format that so far we have accessed with the hand-written code. There is, however, a ready-made module in the Python standard library for working with CSV files: [csv](https://docs.python.org/3/library/csv.html). It works like this:
20
20
21
21
```python
22
22
import csv
@@ -308,7 +308,7 @@ timo;18:42
308
308
kalle;13:23
309
309
```
310
310
311
-
Additionally, the file `submissions.csv` contains points and handintimesfor individual exercises. The format here is `name;task;points;hh:mm`. An example:
311
+
Additionally, the file `submissions.csv` contains points and handingtimesfor individual exercises. The format here is `name;task;points;hh:mm`. An example:
312
312
313
313
```csv
314
314
jarmo;1;8;16:05
@@ -332,7 +332,7 @@ You have the CSV files from the previous exercise at your disposal again. Please
332
332
333
333
The tasks are numbered 1 to 8, and each submission is graded with 0 to 6 points.
334
334
335
-
In the dicionary returned the key should be the name of the student, and the value the total points received by the student.
335
+
In the dictionary returned the key should be the name of the student, and the value the total points received by the student.
336
336
337
337
Hint: nested dictionaries might be a good approach when processing the tasks and submission times of each student.
Copy file name to clipboardExpand all lines: data/part-7/6-more-features.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -171,7 +171,7 @@ Please write a function named `run(program)`, which takes a list containing the
171
171
172
172
You may assume the function will only be given programs which are entirely in the correct format. You do not have to implement any input validation or error handling.
173
173
174
-
This exercise is worth two points. You will receive one point if the commands `PRINT`, `MOV`, `ADD`, `SUB`, `MUL` and `END` are working correctly. You will receice another point if the rest of the commands, which are used to implement loops, also work.
174
+
This exercise is worth two points. You will receive one point if the commands `PRINT`, `MOV`, `ADD`, `SUB`, `MUL` and `END` are working correctly. You will receive another point if the rest of the commands, which are used to implement loops, also work.
175
175
176
176
Below are some examples, which you may also use for testing. Example 1:
0 commit comments