TastyHint2.md
| @@ -49,7 +49,7 @@ class Tasty: | |||
| 49 | 49 | ||
| 50 | 50 | ||
| 51 | 51 | def display_tasks(self): | |
| 52 | - | for task_name, status in enumerate(self.tasks.items()): | |
| 52 | + | for task_name, status in self.tasks.items(): | |
| 53 | 53 | print("- ", task_name, status) | |
| 54 | 54 | ||
| 55 | 55 | ``` | |
TastyHint2.md
| @@ -16,7 +16,7 @@ tasks['Finish Lab'] = 'not yet' | |||
| 16 | 16 | task_name = 'Buy Milk' | |
| 17 | 17 | ||
| 18 | 18 | if tasks[task_name] == 'not yet': | |
| 19 | - | # task is unfinished | |
| 19 | + | # task is unfinished | |
| 20 | 20 | pass | |
| 21 | 21 | else: | |
| 22 | 22 | # task is 'complete' | |
| @@ -25,7 +25,7 @@ else: | |||
| 25 | 25 | ||
| 26 | 26 | # to list all the tasks | |
| 27 | 27 | ||
| 28 | - | for task_name, status in enumerate(tasks.items()): | |
| 28 | + | for task_name, status in tasks.items(): | |
| 29 | 29 | print("- ", task_name, status) | |
| 30 | 30 | ``` | |
| 31 | 31 | ||
TastyHint2.md
| @@ -93,3 +93,13 @@ If I paste the second code block into a Python interpreter... | |||
| 93 | 93 | ``` | |
| 94 | 94 | That's an example of how I might use the rough class here. | |
| 95 | 95 | ||
| 96 | + | And if you're puzzled about my use of `enumerate` - I think now that it is wrong. It should probably be... | |
| 97 | + | ||
| 98 | + | ```python | |
| 99 | + | def display_tasks(self): | |
| 100 | + | for task_name, status in self.tasks.items(): | |
| 101 | + | print("- ", task_name, status) | |
| 102 | + | ``` | |
| 103 | + | ||
| 104 | + | ||
| 105 | + | ||
TastyHint2.md
| @@ -59,7 +59,7 @@ See how those things went from just trial code to _methods_ in the class? | |||
| 59 | 59 | Yes, and... the `self` variable is how you know that thing is a _method_ and not just a _function_. | |
| 60 | 60 | ||
| 61 | 61 | ||
| 62 | - | If I paste the second clode block into a Python interpreter... | |
| 62 | + | If I paste the second code block into a Python interpreter... | |
| 63 | 63 | ||
| 64 | 64 | ```bash | |
| 65 | 65 | >>> class Tasty: | |
TastyHint2.md
| @@ -91,9 +91,5 @@ If I paste the second clode block into a Python interpreter... | |||
| 91 | 91 | - 1 ('Bar', 'not yet') | |
| 92 | 92 | >>> | |
| 93 | 93 | ``` | |
| 94 | - | ||
| 95 | - | ||
| 96 | - | ||
| 97 | - | ||
| 98 | - | ||
| 94 | + | That's an example of how I might use the rough class here. | |
| 99 | 95 | ||
TastyHint2.md
| @@ -59,6 +59,41 @@ See how those things went from just trial code to _methods_ in the class? | |||
| 59 | 59 | Yes, and... the `self` variable is how you know that thing is a _method_ and not just a _function_. | |
| 60 | 60 | ||
| 61 | 61 | ||
| 62 | + | If I paste the second clode block into a Python interpreter... | |
| 63 | + | ||
| 64 | + | ```bash | |
| 65 | + | >>> class Tasty: | |
| 66 | + | ... | |
| 67 | + | ... def __init__(self): | |
| 68 | + | ... self.tasks = {} | |
| 69 | + | ... | |
| 70 | + | ... def add_task(self, task_name): | |
| 71 | + | ... """ | |
| 72 | + | ... Add a new task to the user tasks. | |
| 73 | + | ... """ | |
| 74 | + | ... if task_name not in self.tasks: | |
| 75 | + | ... self.tasks[task_name] = "not yet" | |
| 76 | + | ... else: | |
| 77 | + | ... print("Task already added.") | |
| 78 | + | ... | |
| 79 | + | ... | |
| 80 | + | ... def display_tasks(self): | |
| 81 | + | ... for task_name, status in enumerate(self.tasks.items()): | |
| 82 | + | ... print("- ", task_name, status) | |
| 83 | + | ... | |
| 84 | + | ... | |
| 85 | + | >>> t = Tasty() | |
| 86 | + | >>> t.add_task("Foo") | |
| 87 | + | >>> t.add_task("Bar") | |
| 88 | + | >>> | |
| 89 | + | >>> t.display_tasks() | |
| 90 | + | - 0 ('Foo', 'not yet') | |
| 91 | + | - 1 ('Bar', 'not yet') | |
| 92 | + | >>> | |
| 93 | + | ``` | |
| 94 | + | ||
| 95 | + | ||
| 96 | + | ||
| 62 | 97 | ||
| 63 | 98 | ||
| 64 | 99 | ||
TastyHint2.md
| @@ -17,8 +17,11 @@ task_name = 'Buy Milk' | |||
| 17 | 17 | ||
| 18 | 18 | if tasks[task_name] == 'not yet': | |
| 19 | 19 | # task is unfinished | |
| 20 | + | pass | |
| 20 | 21 | else: | |
| 21 | 22 | # task is 'complete' | |
| 23 | + | pass | |
| 24 | + | ||
| 22 | 25 | ||
| 23 | 26 | # to list all the tasks | |
| 24 | 27 | ||
TastyHint2.md
| @@ -53,7 +53,7 @@ class Tasty: | |||
| 53 | 53 | ||
| 54 | 54 | See how those things went from just trial code to _methods_ in the class? | |
| 55 | 55 | ||
| 56 | - | ||
| 56 | + | Yes, and... the `self` variable is how you know that thing is a _method_ and not just a _function_. | |
| 57 | 57 | ||
| 58 | 58 | ||
| 59 | 59 | ||
TastyHint2.md
| @@ -26,7 +26,7 @@ for task_name, status in enumerate(tasks.items()): | |||
| 26 | 26 | print("- ", task_name, status) | |
| 27 | 27 | ``` | |
| 28 | 28 | ||
| 29 | - | We need to think about how to put _into the class_. | |
| 29 | + | We need to think about how to put thse ideas _into the class_. | |
| 30 | 30 | We might... | |
| 31 | 31 | ||
| 32 | 32 | ```python | |